开发者

How to change file type in solution explorer from Form to Class

I accidentally added some .cs files to project as Form instead of Class. Now in Solution Explorer they keep showing up as Form with Form icon (and opening Designer as default).

How ca开发者_运维知识库n i change them to class type?


  • Unload the project (right click, Unload project)
  • Edit the csproj file (right click, Edit YourProject.csproj)
  • Locate the <Compile> element that refers to your C# file
  • Remove the <SubType> subelement (or change its content from Form to Code)
  • Reload the project


Just create a new class file and copy+paste the code over. Remove the inheritance from Form, too.

If you want to preserve your SVN history try:

  1. Open the folder containing the file
  2. SVN rename only the .cs to a new name
  3. Go to VS, include the renamed file into your project
  4. Remove the inheritance from Form and all cruft like initialize component in your constructor
  5. Delete the old forms file


You could delete the Form class's designer.cs. Then remove inheritance from Form and InitializeComponets() call. In *.csproj file, find the form name and replace respective <SubType>Form</SubType> element.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜