how to create controls dynamically
Hello, I want to create button control at runtime when this button click it shows some label & textbox and another button .when second button click then textbox information is added to database.when first button click then it again generate same label & textbox and button i.e repeat the control as button click.
Suthish NairPosted Feb 27, 2011, 12:20 PM
Suthish NairPosted Feb 24, 2011, 7:57 AM
Jaganathan BantheswaranPosted Feb 24, 2011, 7:54 AM
try this.
Button dynamicButton = new Button();
// Set Button properties
dynamicButton.Height = 40;
dynamicButton.Width = 300;
dynamicButton.BackColor = Color.Red;
dynamicButton.ForeColor = Color.Blue;
dynamicButton.Location = new Point(20, 150);
dynamicButton.Text = "I am Dynamic Button";
dynamicButton.Name = "DynamicButton";
dynamicButton.Font = new Font("Georgia", 16);
// Add a Button Click Event handler
dynamicButton.Click += new EventHandler(DynamicButton_Click);
// Add Button to the Form. Placement of the Button
// will be based on the Location and Size of button
Controls.Add(dynamicButton);
For more details [ recommended article ]
http://www.c-sharpcorner.com/UploadFile/mahesh/1150/