I need to know if it is possible to store click event of a button in
a variable. I tried doing it but didn't get any solution.

Please help


Regards

Event name it self a reference/delegate type variable and you can assign a reference of method (called event handler) to it using (+=) operator.

Please show us your code .

Thanks for your reply.

i haven't written any code yet.
Let me explain you why i need this.

suppose i have two forms; form1 and form2.

on form1 i have 4 buttons. All these buttons open
form2 on click. In form2 i have a data grid view which shows data
of tables(has same name that of button). Now how do i
put this in form2 that which table to show, unless it(form2) knows which button was clicked.

(hey sorry if you find this confusing).

Thanks
ajinkya

Create a new constructor for Form2 that takes a string parameter and store the value in Form2:

String whatTable;

public Form2(String table) {
    whatTable = table;
    InitializeComponent();
}

Now in your button click event you create the form and tell it which table:

Form2 myForm2 = new Form2("GameTable");
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.