What I just did was completely manually:
- Create yourform.Designer.cs
- Add it to Visual Studio (right click, add existing item)
- Add the partial keyword to your existing class.
- Add the namespace exactly like in the original cs to the yourform.designer.cs
- Inside this namespace, add the class definition (don't forget to include the partial keyword). Do not add inheritance and/or interfaces to this partial class in Designer.cs.
- After this is done, you're ready to cut and paste the following:
a) Remove the components object you might have in your original Winform. If the application was .NET 1.1 you will have something like this:
/// <summary>
/// Required designer variable.
/// </summary>
private Container components = null;
b) add a new components object in the Designer class:
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
c) Unless you had a specific dispose method, this is the standard. If you don't have any form Inheritance, I think that base.Dispose can be safety removed:
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose( bool disposing )
{
if ( disposing && ( components != null ) )
{
components.Dispose();
}
base.Dispose( disposing );
}
d) Copy all the code inside the #region Windows Form Designer generated code to the new Designer.cs class.
e) You should also copy all the member variables for all your objects (labels, texboxes, etc. that you use in the designer).
That should be all about it. Save and compile.
Remember that a partial class can be splited among N number of files, but all must share the SAME namespace.
Is it worth?
Well, in my case, I had a bunch of huge winforms with tons of code and controls. VS2008 crawled every time I switched from/to designer. This made the code view more responsive. I remember having to wait for 3-5 seconds before having a responsive code. Now it takes 1…
UPDATE:
Doing steps 1 to 5 and moving an existing or adding a new control won't automatically move anything to the designer.cs class.
New stuff goes to the new Designer class, but old stuff remains where it was, unfortunately.
You also have to close and reopen the file (after you have added/created the partial class) for VS to draw correctly in the Designer; failure to do may result in empty forms being drawn.