Hi all ,
am developing an application using c# language, and i want to create and draw button in my desktop application when the form is loading and opened( i mean don't take it from the Toolbox )after that i want to do something when click on that button that i create when the form is loading, for example i want to insert data to table !!
i need a help by providing me with code to understand this !!!
thank's to all.
i need a help by providing me with code to understand this !!!
thank's to all.
Roy SPosted Jun 20, 2012, 4:19 PM
It's not that hard. Just add an eventhandler for the load event of your form. Instantiate a button, set some properties of that button and add it to the control collection of the form.
private void Form1_Load(object sender, EventArgs e)
{
//instantiate new Button
Button btnNew = new Button();
//edit some properties.. size, location, text
btnNew.Text = "Hello world";
btnNew.Size = new Size(100, 20);
btnNew.Location = new Point(50, 70);
//add an event handler for the click event
btnNew.Click += btnNewClick;
//add the button to the controls
this.Controls.Add(btnNew);
}
private void btnNewClick(object sender, EventArgs e)
{
//method for the click event.
MessageBox.Show("You clicked the button");
}
younis abdeljawwadPosted Jun 21, 2012, 5:19 AM