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

Total Post:135

Posted on    September-04-2013 1:43 AM

 C# C# 

 1 Reply(s)
 544  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();



private void b2_click(object sender, eventargs e)


    form1 f1=new form1();



Sumit Kesarwani

Total Post:378

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:


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