I WANT TO STORE THE BUTTON TEXT WHICH CALLED THE WINDOW FORM

Chintoo Semi

Total Post:135

Points:947
Posted by  Chintoo Semi
C# 
C#
 742  View(s)
Ratings:
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();

}

  1. Sumit Kesarwani

    Post:378

    Points:2694
    Re: I want to store the button text which called the window form

    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.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!