views:

172

answers:

2

When creating form windows, often there are situations where a particular event was added and the program comipled.However later u realize that the event is not really required and so remove the event. Now when u compile the code again an error is displayed. For example in the code I have written: WindowsAplication1.LanMessenger does not contain a definition for 'textBox1_click'.

Obviously it es evident that i removed the event textBox1_click after compiling it once before. Is there any way this can be avoided because it does get a touch annoying when you know there is no prob actually.. Please help.

+2  A: 

You need to look in the MyFormName.Designer.cs and look for the area where your particular controls properties are set. You should notice a line to the effect of:

this.textBox1.Click += new EventHandler(textBox1_click);

You need to remove this line and save the file.

Just a note, these are considered designer generated events, what you could do is wire up your own events for your controls either in your constructor (after the call to InitializeComponent) or in a Form_Load event that you can also setup in the constructor. This method is nice because you have clear control and ability to see exactly what handlers are setup.

Quintin Robinson
+1  A: 

The cleanest way to avoid the error is to do the following

  1. Navigate to the event in the designer and clear out the handler
  2. Delete the actual event code.

There is no one step way to delete both the event and the event connection in VS 2005/VS 2008. Personally I do the following because I find it to be faster

  1. Delete the event handler
  2. CTRL-B to build (this will generate a build error at the event hookup location
  3. ALT-F7 to switch to error list
  4. Down to get to the first error
  5. Enter navigates to the event hookup
  6. Delete the line.

This is a really fast progression if you use ViEmu :)

JaredPar