locked
designer.cs cleanup RRS feed

  • Question

  • Hi Everyone,

    I've been making a windows forms application in C# and its gone through a lot of changes in terms of components used etc.

    I've added and deleted quite a few but the designer.cs file hasn't removed the elements that I have physically removed from the GUI.

    Is there a way in visual studio to perform a cleanup (ie check to see what's on the form, and remove the rest) from the designer cs file or do I have to do this manually?

    Thanks

    David
    Thursday, January 31, 2008 12:14 PM

Answers

All replies

  •  

    Hi Isador,

    As far as I know, Visual Studio doesn’t provide this function. Since there is an attribute named DesignTimeVisible, which can let you set the visibility for components that have none UI presence. So the designer may not know which invisible component you want to delete.

    More information, please visit:
    http://msdn2.microsoft.com/en-us/library/system.componentmodel.designtimevisibleattribute(VS.80).aspx

    Hope this helps.
    Best regards.
    Rong-Chun Zhang

    Tuesday, February 5, 2008 4:02 AM
  • I had the same problem. So, I did it manually!!! If you follow these steps it can't go wrong (make a backup any way LOL)

    1) There are 3 parts in the .Designer.cs file:

    a. Windows Form Designer generated code has 2 parts:

    a.1 Declaration Part (e.g. this.menuStrip1 = new System.Windows.Forms.MenuStrip(); etc...

    a.2 Properties Part (e.g. this.overviewToolStripMenuItem.Name = "overviewToolStripMenuItem"; etc...

    Don't touch them yet!

    2) At the bottom you find the constructors (e.g. private System.Windows.Forms.MenuStrip menuStrip1; etc...

    Delete the ones you want to get rid off

    3) Loads of errors appear

    4) Go to part one and delete all lines with "red underlined" components

    5) Go to part two and delete all and the complete blocks (marked with comments) with "red underlined" components

    6) No more errors (otherwise you missed a few)

    7) F6 Build / Save

    DONE

    Worked for me.

    PS. Did I mention this is at your own risk? If not...THIS IS AT YOUR OWN RISK, DON'T BE UPSET WITH ME IF IT GOES WRONG, IT CLEARLY STATES "DON'T CHANGE THIS GENERATED CODE".

    Friday, August 26, 2011 10:51 AM