0

When I try to delete those empty handlers the form gets broken. How can I remove those annoying codes from my program without affecting form?

enter image description here

1
  • 2
    Could you add this code here as a snippet, not a screenshot? Commented Mar 14, 2016 at 7:26

1 Answer 1

5

When you delete the btnOrder_Click you should also delete the following line in yourForm.Designer.cs:

this.btnOrder.Click += new System.EventHandler(this.btnOrder_Click);

To find this line after you removed the btnOrder_Click rebuild your project and then in the Error List window double click on error which says:

'WindowsFormsApplication1.Form1' does not contain a definition for 'btnOrder_Click' and no extension method 'btnOrder_Click' accepting a first argument of type 'WindowsFormsApplication1.Form1' could be found (are you missing a using directive or an assembly reference?)

By double clicking on this error you will redirect to that line and after deleting that line your form returns back.

Sign up to request clarification or add additional context in comments.

3 Comments

This technique is called "Leaning on the compiler" and I'm a fan of it :) +1
Also from Properties window: events tab > right click on event > reset
This is why it is annoing to hear people say: NEVER EDIT THE DESIGNER FILE MANUALLY! If you have deleted the event handler in the .cs file, you have to manually delete the rest in the designer file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.