简体   繁体   中英

Doesn't contain a definition for XXX error

If I accidentally double-click a button on a Winform in the visual studio designer an event handler is added. Deleting the event handler causes the compiler to throw an error indicating that the class definition does not contain the event handler. How do I fix this issue?

You need to delete the reference to the event in the designer code created by visual studio. I don't recommend going into the code itself, since you can mess stuff up.

Select the button in the designer, and open the properties toolbar. Go to the events tab in the properties toolbar. Find the "OnClicked" or "Clicked" event and remove the method associated with it. Now you can delete that event in your code and it shouldn't complain.

Select the button on which you double-clicked in the forms designer and hit the f4 key to bring up the properties window. Then ensure you click on the events filter at the top of the properties window and clear the event handler property for the appropriate event.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM