how do you wire your own form control event handlers

  • Thread starter Daniel Billingsley
  • Start date
D

Daniel Billingsley

If you double click on a control on a form in the designer it writes the
handler stub and links it for what I guess is considered the "default" event
of the control. Double-click on a form, for example, and you get a _Load()
handler. The link is handled in the InitializeComponents() method, which
the designer places in the "...generated code" region with the comments "...
do not modify the contents of this method...".

I know intellisense does most of the work for you if you type "control.event
+="... but my question is where do you put this code if you're not supposed
to add to InitializeComponent()?

What I've done is created a CustomInitializeComponent() and added its call
in the constructor right after the one to InitializeComponent().

Does that sound good?
 
M

Martin Robins

That sounds fine. Otherwise, you can view the list of events from the
properties window (click on a control, then click on the lightning at the
top of the properties window) and then you can see all of the available
events and add handlers as you wish; VS will then add these to the
InitialiseComponent method for you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top