Parth48
asked on
how can i create button click event dynamically through C# coding in window application ??
here i create 3 buttons dynamically in form load event ...
please refer the below code ...
but now how can i create button click event for above buttons dynamically through coding ??
give me some suggestions ...
please refer the below code ...
private void Form1_Load(object sender, EventArgs e)
{
//get form properties
objGeneral.GetFormProperties(this.FindForm());
//Dynamically create buttons
//button 1
Button btnSqlServerCheck = new Button();
btnSqlServerCheck.Text = "Check MS SQL Server Installation";
btnSqlServerCheck.Location = new Point(45, 27);
btnSqlServerCheck.Size = new Size(200, 25);
this.Controls.Add(btnSqlServerCheck);
//button 2
Button btnAccessCheck = new Button();
btnAccessCheck.Text = "Check MS Access Installation";
btnAccessCheck.Location = new Point(45, 70);
btnAccessCheck.Size = new Size(200, 25);
this.Controls.Add(btnAccessCheck);
//button 3
Button btnExcelCheck = new Button();
btnExcelCheck.Text = "Check MS Excel Installation";
btnExcelCheck.Location = new Point(45, 113);
btnExcelCheck.Size = new Size(200, 25);
this.Controls.Add(btnExcelCheck);
//button click events
}
but now how can i create button click event for above buttons dynamically through coding ??
give me some suggestions ...
Sample
private void Form1_Load(object sender, EventArgs e)
{
//get form properties
objGeneral.GetFormProperties(this.FindForm());
//Dynamically create buttons
//button 1
Button btnSqlServerCheck = new Button();
btnSqlServerCheck.Text = "Check MS SQL Server Installation";
btnSqlServerCheck.Location = new Point(45, 27);
btnSqlServerCheck.Size = new Size(200, 25);
this.Controls.Add(btnSqlServerCheck);
//button 2
Button btnAccessCheck = new Button();
btnAccessCheck.Text = "Check MS Access Installation";
btnAccessCheck.Location = new Point(45, 70);
btnAccessCheck.Size = new Size(200, 25);
this.Controls.Add(btnAccessCheck);
//button 3
Button btnExcelCheck = new Button();
btnExcelCheck.Text = "Check MS Excel Installation";
btnExcelCheck.Location = new Point(45, 113);
btnExcelCheck.Size = new Size(200, 25);
this.Controls.Add(btnExcelCheck);
//button click events
btnExcelCheck.Click += new EventHandler(btnExcelCheck_Click);
}
void btnExcelCheck_Click(object sender, EventArgs e)
{
throw new NotImplementedException();
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
private void Form1_Load(object sender, EventArgs e)
{
//get form properties
objGeneral.GetFormProperties(this.FindForm());
//Dynamically create buttons
//button 1
Button btnSqlServerCheck = new Button();
btnSqlServerCheck.Text = "Check MS SQL Server Installation";
btnSqlServerCheck.Location = new Point(45, 27);
btnSqlServerCheck.Size = new Size(200, 25);
this.Controls.Add(btnSqlServerCheck);
//button click events
btnSqlServerCheck.Click += new EventHandler(btnSqlServerCheck_Click);
//button 2
Button btnAccessCheck = new Button();
btnAccessCheck.Text = "Check MS Access Installation";
btnAccessCheck.Location = new Point(45, 70);
btnAccessCheck.Size = new Size(200, 25);
this.Controls.Add(btnAccessCheck);
//button click events
btnAccessCheck.Click += new EventHandler(btnAccessCheck_Click);
//button 3
Button btnExcelCheck = new Button();
btnExcelCheck.Text = "Check MS Excel Installation";
btnExcelCheck.Location = new Point(45, 113);
btnExcelCheck.Size = new Size(200, 25);
this.Controls.Add(btnExcelCheck);
//button click events
btnExcelCheck.Click += new EventHandler(btnExcelCheck_Click);
}
void btnExcelCheck_Click(object sender, EventArgs e)
{
throw new NotImplementedException();
}
void btnAccessCheck_Click(object sender, EventArgs e)
{
throw new NotImplementedException();
}
void btnSqlServerCheck_Click(object sender, EventArgs e)
{
throw new NotImplementedException();
}
sample
Open in new window