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 fromForm
toCode
) - 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:
- Open the folder containing the file
- SVN rename only the .cs to a new name
- Go to VS, include the renamed file into your project
- Remove the inheritance from
Form
and all cruft like initialize component in your constructor - 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.
精彩评论