Home > DeveloperSection > Forums > I want to store the button text which called the window form
Chintoo Semi

Total Post:135

Points:947
Posted on    September-04-2013 1:43 AM

 C# C# 
Ratings:


 1 Reply(s)
 568  View(s)
Rate this:

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

Total Post:378

Points:2694
Posted on    September-04-2013 3:31 AM

Hi Chintoo,

There 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.


Don't want to miss updates? Please click the below button!

Follow MindStick