How to automatically convert VS2003 classes to partial Designer.cs files?

天涯浪子 提交于 2019-12-03 06:39:21

There is a macro out there floating that does this. I have used it and it works great. Start by looking at Nathan Jones Blog. If you dont have much luck then download a zip of the macro source (I posted) from VSCONVERT - PasteBin

The original classes will continue to work - even with the Visual Studio designer. The code the VS puts in the Designer classes is simply meant to remove the designer "noise" into a separate file so you can focus on the non-visual code in your class.

Once you migrate the project to VS2008 using the wizard, you can open up your forms in VS and continue to edit them just like you did before. Any new forms that you create will get Designer backer files.

We had this problem.

Basically the designer file should contain nothing but a set of object declarations (i.e. the objects on the form) and the InitializeComponent() call. If you've done any fancy work on your constructor that might be there too.

Simply create a file called MyForm.Designer.cs and add it to the project. VS2008 will automatically place it underneath MyForm.cs. From there, if you create the partial class heading and the namespace, then copy across all the declarations and Initializecomponent call into the designer file, then it will work.

But because if you had to, people would edit initializecomponent and also edit the default constructor, VS2005 and 2008 couldn't automatically upgrade these files as all sorts of strange things might occur. I guess from a project point of view, what benefit do you think your working code will derive from the separation?

I'm not sure I understand, but I'll make a guess.

Was this an ASP.NET project in VS2003? Did it have .Designer.cs files in it? Is it the case that you've done an upgrade but you find that you have no .Designer.cs files now?

If so - you may have inadvertently changed your Web Application Project into a Web Site "project". This sort of "project" was introduced in VS2005, so you would not have seen it yet. These aren't real projects (no .csproj file), and they have many other differences.

Otherwise, if your project didn't used to have .Designer.cs files, then why do you want them now?

In general, the way to create designer files is to open the file in a designer, wait a few moments for the designer to finish what it's doing (updating the screen, etc); and then saving the file. You might possibly have to "touch" the original in order to get the designer to reevaluate things.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!