views:

20

answers:

2

I started looking into the designer file of one of my Forms and noticed that a lot of the old controls I thought I had deleted are still being instantiated but are not actually used on the form.

Is there any easy way to clean up these controls from the designer file that are not being used? Right now I've printed out a list of all the private fields at the bottom of the designer file that reference the controls of the form. I'm going down the list one by one trying to determine if the control is actually used or not, and then deleting those that I find are not on the form. The document outline is useful for figuring out what controls are on the form, but this is still a rather tedious process. Does anyone have a better way?

+1  A: 

That's a bit strange. The point of creating a control is to have something visible in the UI, something the user can interact with. Useless controls should be readily apparent in the UI.

If that's not clearly observable from the UI then these controls either set their Visible property to false or their Location property to a value to keeps it out of view. Something to look for.

The only other way you've got is to open the Designer.cs file, located the list of control variable names and right-click them one by one. Select "Find all references" and if you don't see a source code file listed other than the designer file listed then it might be a candidate for deletion. You next have to check their event handlers, same way.

Hans Passant
Yeah see the problem is the initialization code for the unused controls is still there though. So Find All References still returns something for controls that aren't being used. I was able to get through the whole file by hand, but it was quite a pain.Any idea how I was able to remove controls from the form with out them being removed from the designer file?
Eric Anastas
A: 

Hans' suggestion of using "Find all references" is most likely the best option. If, however, the majority of these are not being used, you may be better off just commenting out the entire declaration block for controls in the .designer.cs file, and then using the compiler errors to help you list the controls that are being used, uncommenting them one (or more) at a time until it compiles again. This will prevent you from missing any, and use the compiler to help.

Both of these options are going to be at least somewhat tedious, however.

Reed Copsey