Reputation: 8959
I have an annoying problem. Sometimes Visual Studio does not show option "View designer" for some of my forms in solution explorer. It does not show design mode errors, just doesn't show option to use the designer. I cannot figure out exact cases when this happens.. Does anybody have some ideas about what causes such behavior of solution explorer?
Upvotes: 6
Views: 5387
Reputation: 1
Experienced same issue with Visual Studio 2017
I found the following solution:
Doing the work around recommended by user2205930 might allow you to keep your custom class to the top of form.
Upvotes: 0
Reputation: 11
If you have multiple classes in the file (shame on you), make sure the Form class is the first in the file. (Don't ask me how I know this.)
Upvotes: 0
Reputation: 1003
This will occur if the first class in the source file is NOT the "partial class" for your form. In this case the file type icon in solution explorer will initially display as a form but VS will change it to the "C#" code icon after it has loaded the file and also remove the "View Designer" option from the popup menu. At least in VS2015 this can be fixed by commenting out the offending code and saving the file at which time VS will restore the expected form icon.
Upvotes: 5
Reputation: 103
I've had this problem too, i've modified the .csproj file to fix it. In my .csproj file i modified this line of code:
<Compile Include="FormName.cs" />
With this code:
<Compile Include="FormName.cs">
<SubType>Form</SubType>
</Compile>
Upvotes: 4
Reputation: 1086
I've had this problem and found a solution. Somehow my .csproj file got corrupted and was missing a subkey in the XML. Say for instance I have a UserControl called MyControl.cs, my corrupted XML in .csproj looked like:
<Compile Include="MyControl.cs" />
I fixed it so it now reads:
<Compile Include="MyControl.cs">
<SubKey>UserControl</SubKey>
</Compile>
MyControl.cs reads like (this is just for completeness):
public partial class MyControl : UserControl
{
}
After making that change and saving Visual Studios now correctly reads my control and loads the designer. I have no idea how this file became corrupted.
Upvotes: 0
Reputation: 888107
Your forms are probably inheriting a custom form class.
There may be times when VS doesn't realize that the custom class inherits Form
. (eg, if the solution doesn't build).
Try rebuilding the solution.
If you want a more precide answer, please provide more details.
Upvotes: 3
Reputation: 9244
I used to have that problem a lot in VS 2003. Each time it happened, I opened up the .csproj file in Notepad and changed the of the class back to "Form".
Upvotes: 1