# Sunday, September 21, 2008

Any  forms/user controls added to a project after the VS2005  release are broken into partial classes. 

 

 

The Designer.cs part of the class contains the InitalizeComponent method, the dispose method, and the control declerations.  This makes the forms easier to work with.

 

When upgrading an old VS2003 project to 2005 it doesn’t automatically break up this code.  The old VS2003 forms and user controls can be updated to pull this code out so they’re easier to work with too. 

 

Step #1 Check out the form

 

Step # 2 Create a copy of the file and rename one of the files to end with Designer.cs

 

 

 

 

Step #3 Open the files in VS2005 outside of the project.  Just open the files directly. 

 

From the Form.CS file remove the InitializeComponent(), dispose, and control declarations

From the From.Designer.CS file remove everything BUT the InitializeComponent(), dispose, and control declerations

 

*Note that the designer file doesn’t need the using statements. 

 

Step #4 Set the class as a partial class

 

The designer file

 

 

 

From the cs file

 

 

Step #5 Reopen the project. Right click on the designer file and select Include In Project. 

 

 

 

 

 

Step #6 Do a Rebuild

 

Step #7 Makes sure the form designer opens

 

 

 

 

This does checkout the project file remember to turn the project file in when done. 

 

This refactoring makes the cs files smaller which makes them faster and easier to work with in VS

C# | Winforms
Sunday, September 21, 2008 5:46:43 PM (GMT Standard Time, UTC+00:00)
Comments are closed.
Search
Navigation
On this page....
Archives
<March 2010>
SunMonTueWedThuFriSat
28123456
78910111213
14151617181920
21222324252627
28293031123
45678910
Aggregate Me!
Feed your aggregator (RSS 2.0)
More proof I'm a geek

Categories
Blogroll
Contact me
Send mail to the author(s) E-mail