简体   繁体   中英

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 can 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM