title: C# WinForms, remove unused controls
body: <p>I'm working on a C# project (.net 3.5, visual studio 2008) and have a quick question for yo all:</p>
  
  <p>Is is possible to remove controls that are never used?</p>
  
  <p>By that I mean, is it possible to remove controls that have been added to the form but haven't been referenced anywhere in the code base (outside of the designer)?</p>
  
  <p>The WinForms stuff I'm looking at has tens of controls with generic names ("textBox1, button 4, etc) that are not used by the code base (or even seen by the user).</p>
  
  <p>Most of the form has controls on top of controls (not my decision), and there's a lot of layering of panels and splitters. This has lead to a situation where there are controls hidden from view, which never get used or attached to any event handlers.</p>
  
  <p>I'm worried that these extra controls are going to leave a big memory footprint, or lead to performance issues - I've already seen the form become laggy after a ~10 minutes of use.</p>
  
  <p>Obviously, I don't want to jump into the designer file and start removing references to controls that aren't necessary. the code base is checked into source control, but there have been many, many, <strong>MANY</strong> commits since it was first checked in.</p>
  
  <p>I was thinking iterating through the following pattern:</p>
  
  <ul>
  <li>Cut a panel</li>
  <li>Paste it into a new (empty) project</li>
  <li>Remove any controls that I know are not used in the main project (anything with a generic name)</li>
  <li>Paste the panel back into the main project and re-build (to check for errors)</li>
  </ul>
  
  <p>Are there any (potentially) faster ways of doing this? Are there any safer ways of doing this? Are there any 3rd party tools that I can run against the code base (similar a profiler, maybe?) that can tell me which controls should be removed?</p>
  
  <p>Thanks</p>