Just deleting the event handler isn't enough. You also need to remove the
line of code that registers the event handler with the event. For example,
to remove the Load event for a form called 'MyForm' you need to delete two
things:
1. private void frmMyForm_Load(object sender, System.EventArgs e) { // some
code } (the event handler)
2. this.Load += new System.EventHandler(this.frmMyForm_Load);
The former is the event handler itself, the latter is the line of code that
attaches this event handler to the Load event. You'll find this line in the
*Windows Forms Designer generated code* region.
There is an easier way to do this, though. Go back to the control's
properties and open the events, just like you did to add the event. Select
the name of the event handler next to the event in the list. Delete this
method from the event list. This will remove the code. If there was no code
in the event handler, the handler itself will also be deleted from your
code. If you already wrote code, you still have to delete this method
manually, but all other code related to this event is removed automatically
by VS.
--
Kai Brinkmann [MSFT]
Please do not send e-mail directly to this alias. This alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.
"vbMark" <no@email.com> wrote in message
news:Xn************************@130.133.1.4...
"Kai Brinkmann [MSFT]" <ka******@online.microsoft.com> wrote in
news:uj**************@TK2MSFTNGP09.phx.gbl:
The easiest way is to let VS do most of the work. You can simply
double-click on the control to add an event handler for the control's
default event to your code. For other events, click on the control in
the designer. Next, click on the event icon (the flash of lightning)
in the properties window to display the pre-defined events for this
control. Double-click on the name of the desired event to have VS add
an event handler to your code.
VS writes all necessary code (attaching the event handler to the
event, etc.) behind the scenes. You can view this code by expanding
the region 'Windows Form Designer generated dode.' All you'll have to
do is write the code you want the event handler to execute. Of course
this only works for pre-defined events. If you want to create your own
event, you'll still have to go through the usual steps of creating a
delegate object, defining and publishing the event, and attaching the
event handler(s).
Hope this helps.
If I've added an event that I don't want what's the best way to delete it?