I am working on a forms application with a button. When I double click on it on the designer form, it automatically creates a private void saveButton_Click() function.
How do I delete this function without generating errors in Visual Studio 2012? If I delete the method, it will create an error that states "File does not contain a definition for saveButton_click() and no extension method 'save_button_click'. So how would I delete this method completely as I accidentally created this when I double clicked on the button on designer form?
I can't undo as I have done other changes before trying to fix this. Should I delete something from another file in Visual Studio 2012?
EDIT: I cannot undo (CTRL - Z) as I have saved the files and done other changes as stated above. What I am looking for is a way for Visual Studio to remove all event handlers of when the button is double clicked automatically.
You see this error message, because Visual Studio adds two things when you are double-clicking button:
1) It creates empty event handler in code file
void saveButton_click(object sender, EventArgs e)
{
}
2) In designer generated code file it subscribes this handler to button click event
saveButton.Click += new EventHandler(saveButton_click);
When you remove handler, you still have it referenced in designer file. And compiler can't find saveButton_click
method which you just removed.
If accidental button click is the only change you made, then just click Ctrl-Z
and operation will be reverted (both handler and event subscription will be removed). In this case you will see this dialog box, don't afraid to click Yes
Otherwise you should remove subscription (either manually, by editing designer file, or from designer) and remove handler (only manually).
Winforms - Visually remove button click event
This shows how to remove event handlers using Visual Studio 2012. F4 and under the properties tab.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With