开发者

How to remove unused Clicked event from C# project

开发者 https://www.devze.com 2023-02-14 09:10 出处:网络
I am newbie in C#. while working in Windows Forms Designer if any controls get double-clicked by mistake it places the clicked event on the Form.cs (ie: private void UserAddBtn_Click(object sender, Ev

I am newbie in C#. while working in Windows Forms Designer if any controls get double-clicked by mistake it places the clicked event on the Form.cs (ie: private void UserAddBtn_Click(object sender, EventArgs e). how can I remove all the r开发者_开发问答eferences of this event while staying in Forms designer or w/o going thru manual removal.

Thanks in advance....


You can clear the event handler by deleting it from the properties dialog.

Go to the events tab and find the double click event. You can then delete the event handler from there.


if you select the item you want to remove in the form designer, then right click on the lightning bolt and click "reset" it works for me. I couldn't make it work as explained above. I'm using Visual studio express 2013 V12 - Update 4.


In the designer view, click undo (Ctrl + Z) - this will undo the generated event handler in the code-behind as well as all bindings to the event handler in the .designer.cs autogenerated. Do not perform the undo in the event handler codebehind, because this will remove the event handler, but leave the bindings to it.

NOTE: If you add any code to the event handler, then undo will only remove the bindings - the event handler will get left behind. This is to make sure you don't lose anything you added that might be important.


I am privy to doing this myself lol. However, it is quite simple (I am using Visual Studio 2017). Delete the unused event and try to run while not debugging. Select no and look at the bottom where it lists the errors. Double click the red "X". Visual Studio will direct you to the next error. Delete that and you should be good to go (Should be a .Click event handler). Whether this works in all scenarios this simply I am not sure but if you have no code in that block then there should not be too much more complexity.


Go to the event handler -> Find All References -> go to the reference and delete it. Then delete the event handler.

0

精彩评论

暂无评论...
验证码 换一张
取 消