How to create an click event in a form automatic(C#)

  • Thread starter Thread starter Baboon
  • Start date Start date
B

Baboon

Hello

Now i have try create an click event in a form,so i doubleclick the form,but
the IDE create an form_load event automatic:

private void Form2_Load(object sender, System.EventArgs e)
{ }

but the code i need is:

private void Form2_Click(object sender, System.EventArgs e)
{ }

so i had write it by hand,but it not work,i find some books,and add some
codes:

this.Click += new System.EventHandler(this.Form2_Click);

Haha,it work,but how can IDE create an click event automatic,not with
handwrite?
 
Baboon said:
Now i have try create an click event in a form,so i doubleclick the
form,but the IDE create an form_load event automatic:

Select the form/control and click the small lightning button in the
properties window. Choose the desired event and add a handler.
 
Thanks you answer! But it doesn't work correct.

I click the lightning button ,it take me to the event's load,what is show me
is an empty combBox,i write an event "Form_Click",push enter ,the IDE create
code:
private void Form1_Click(object sender, System.EventArgs e)
{

}
and other code in InitializeComponent:
this.Load += new System.EventHandler(this.Form1_Click);

then i complet the code,push F5,debug it .
Now something which i hope to happen when i click done already,it happen
when the form load,so i change the code:
this.Load += new System.EventHandler(this.Form1_Click);
to:
this.Click += new System.EventHandler(this.Form1_Click);
then the program done with my wish.

It's so interesting,i don't know why?
Don't tell me i need to format the c:/ and install the VS again,it not a
good idea!
 
Hi Baboon,

just double-klick in the comboBox of the desired event then vs.net will
create the code pattern for you automatically.

Sincerly,
Christian
 
Thanks very much!
I find the correct comboBox,and it done with my wishes.
Thanks again!!!
 
Back
Top