Dynamic click event
i have create 10 buttons dynamic buttons and give button text as 1 to 10 after that i want click that buttons after it generate in form.when i click 5th button it is show Button: 5 in message box it means what ever you click that button text only display in message box.
Surendra KandiraPosted Jan 28, 2016, 2:22 AM
{
Button newLabelSection = new Button();
// bug fix 0000013
newLabelSection.Text = i.ToString();
newLabelSection.ID ="btn"+i;
newLabelSection.Height = 40;
newLabelSection.Width = 50;
newLabelSection.Click += new System.EventHandler(this.sectionListItem_Click);
Panel1.Controls.Add(newLabelSection);
}
{
var text = ((Button)sender).Text;
}
{
newLabelSection.Text = i.Tostring();
newLabelSection.Size = new System.Drawing.Size(40, 50);
newLabelSection.Location = new System.Drawing.Point(sectionListPanel.Width, 0);
newLabelSection.Margin = new System.Windows.Forms.Padding(3);
newLabelSection.UseVisualStyleBackColor = true;
newLabelSection.Tag = i;
newLabelSection.Click += new System.EventHandler(this.sectionListItem_Click);
sectionListPanel.Controls.Add(newLabelSection);
{
var text = ((Button)sender).Text;
}
Manas MohapatraPosted Jan 28, 2016, 2:22 AM