VS.NET overwrites my event handlers

G

Guest

I'm working on a windows forms application and some of my controls have
multiple event handlers assigned to them. I haven't figured out how to add
multiple event handlers via the properties window, so I do it manually.
However, it seems that whenever I bring up a properties window, VS removes
one of my handlers, from each control that has more than one handler. Please
help!
How can I get this to stop??
 
N

nick_nw

jrett said:
I'm working on a windows forms application and some of my controls have
multiple event handlers assigned to them. I haven't figured out how to add
multiple event handlers via the properties window, so I do it manually.
However, it seems that whenever I bring up a properties window, VS removes
one of my handlers, from each control that has more than one handler. Please
help!
How can I get this to stop??

Where abouts in your code are you writing the manual event handlers?

It should be done in the form's constructor, not in the windows
generated region.

Nick
http://seecharp.blogspot.com/
 
G

Guest

Also, it turns out that if the event handler that it removes from a control
isn't referenced elsewhere, it actually deletes my event handler method!
This is really bothersome.
 
B

Bruce Wood

jrett said:
I'm working on a windows forms application and some of my controls have
multiple event handlers assigned to them. I haven't figured out how to add
multiple event handlers via the properties window, so I do it manually.
However, it seems that whenever I bring up a properties window, VS removes
one of my handlers, from each control that has more than one handler. Please
help!
How can I get this to stop??

Where are you putting the code to subscribe to the events?

If you are trying to put it all together in the section of code that
the Designer has marked off for itself... well, that bit says, "Don't
change this code!" for a good reason.

You can specify one handler for the event using the Designer, if you
like. The rest you must subscribe to somewhere else: many people do it
in the constructor, after the InitializeComponent() call. I like to do
it in the OnLoad() method for the form.

Either way, don't go hand-modifying the code that the Designer
generates, or, as you've seen, it will overwrite your changes next time
you change something on the form.
 
B

Bruce Wood

jrett said:
Also, it turns out that if the event handler that it removes from a control
isn't referenced elsewhere, it actually deletes my event handler method!
This is really bothersome.

Exactly how do you get that to occur? Which version of .NET are you
using? I'm using .NET 1.1 and I have never, ever had the Designer
delete an event handler method.
 

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