Reputation: 681
I am working on a project that I had left all the controls with default names until recently. Multiple times at the start of the project, I accidentally double-clicked something and it created an event handler for that control. At the time I didn't know how to remove them, because Ctrl+Z would undo far more than I wanted.
I now know that I can view and refactor the events that are being used by a control in the Events
section of the Properties
windows. I have mostly fixed these problems but I have a function called TabPage4_Click
that I can't find a control that is actually using it. I don't have a TabPage4 anymore, I have renamed everything at this point, and none of my tab pages are using this event handler, but my application fails to compile if I remove it.
At this point, there are far too many controls on my form to check them one-by-one to find out if any of them is using this event handler. I am wondering if there is any way for me to view a list of event handlers and the controls that are using them. Is there any way in Visual Studio 2010 to easily track down what control is currently using an event handler so that I remove it without creating any conflicts?
Upvotes: 1
Views: 1565
Reputation: 71187
Avoid using the designer for anything other than adding controls onto your form. You'll find events and event handlers much easier to manage if you're explicitly registering their events upon form initialization:
void RegisterControlEvents()
{
myButton.Click += MyClickHandler;
...
}
void MyClickHandler(object sender, EventArgs e)
{
...
}
Soon you'll find yourself not using the designer at all...
As for dead code, delete it and try building; if there's a reference, VS will tell you where the deletion broke your code / where to go to fix it.
If you're looking for a tool, I'd say get the ReSharper demo. I don't think anything else compares (no I don't work for JetBrains/ReSharper, it's just an amazing tool for that).
Upvotes: 2