Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Click EVent Misunderstaninding

Posted on 2006-06-21
3
Medium Priority
?
194 Views
Last Modified: 2010-04-16
Hi, please can somebody explain to me how events works with C# Windows Programming. I mean take this for example.  In the form I add a button, I then double click this button and it takes me into the code, where it generates an event.

        private void button1_Click(object sender, EventArgs e)
        {
           
        }

Now, I thought ok, I will create one manually without double clicking it. So I add another button underneathe it called button2 and then I go into the code and manually type this

        private void button2_Click(object sender, EventArgs e)
        {
           
        }

When I double click the button and it generates the code then it will fire the Click event. But in the case of button2, when I manually write the code it does not fire.

I am obviously missing the method of attaching the event to the button.

thanks in advance

Andrew
0
Comment
Question by:REA_ANDREW
  • 2
3 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 2000 total points
ID: 16949576
Right-click on button1_Click and select "Find all references". You will see the following line generated by Windows Form Designer when you double-click button:

this.button1.Click += new System.EventHandler(this.button1_Click);

Designer-generated code is placed in separate file (2005 version) or in the same file (precious versions). This line subscribes to Click event. To do the same manually add the following code to form constructor or Load handler:

this.button2.Click += new System.EventHandler(this.button2_Click);
0
 
LVL 20

Author Comment

by:REA_ANDREW
ID: 16949597
GOTCHA

So all events I want to declare for any object, I put in the Form.Designer.cs file , under the intialize component.

0
 
LVL 48

Expert Comment

by:AlexFM
ID: 16949767
No, Form.Designer.cs file is file managed by Form Designer, don't make any changes in it. You have Form.cs file to write your own code.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month8 days, 3 hours left to enroll

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question