On form 1 I want to store the name of the button which called this form so that i can execute some code depending upon the button click
button bt1=new button();
button bt2=new button();
private void b1_click(object sender, eventargs e)
{
form1 f1=new form1();
f1.show();
}
private void b2_click(object sender, eventargs e)
{
form1 f1=new form1();
f1.show();
}
Sumit Kesarwani
04-Sep-2013There are multiple ways of doing this, I suggest one of the following ways
Using the forms constructor:
ie
form1 f1 = new form1("MyButtonName");and then in the constructor of the form
public form1(string buttonName)
{
this.ButtonName = buttonName;
}
or setting the property manually
form1 f1 = new form1();
f1.ButtonName = "MyButtonName";
I prefer using the former, as it forces you to specify the button that creates the new form.