ironic
ironic

Reputation: 8959

Visual Studio forms designer

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

Answers (7)

iamzoilus
iamzoilus

Reputation: 1

Experienced same issue with Visual Studio 2017

I found the following solution:

  1. (root cause): Added custom class to top of the form1.cs file
  2. (symptom): Design view now missing (right click the form class in solution explorer, "view designer" not shown)
  3. (solution): Move the Form class back to the top of the file. "view designer" now properly showing

Doing the work around recommended by user2205930 might allow you to keep your custom class to the top of form.

Upvotes: 0

ChristianGeek
ChristianGeek

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

eric gilbertson
eric gilbertson

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

Alessandro Perfetti
Alessandro Perfetti

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

user2205930
user2205930

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

SLaks
SLaks

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

Dan Bystr&#246;m
Dan Bystr&#246;m

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

Related Questions