6

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?

4
  • what version of VS? If VS 2005, make sure you are running the latest SP.
    – user195488
    Dec 28, 2009 at 16:20
  • Are any of the forms you're trying to design using visual inheritance? And what happens if you open the code editor and press F7?
    – Rory
    Dec 28, 2009 at 16:20
  • 1
    This works only for forms which VS understands to be forms.
    – ironic
    Dec 28, 2009 at 16:25
  • @SLaks: Yeah, that's the one, I hardly ever use the hotkey to get back to designer view.
    – Rory
    Dec 28, 2009 at 16:28

7 Answers 7

5

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.

1
  • This was definitely my issue. Good call. Feb 12, 2017 at 14:35
4

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>
3

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.

5
  • Yes, it seems to be the problem.. Changing base type to Form, and then back to MyCustomDialog helps, but is there a way to make VS analyze if my form is a form?
    – ironic
    Dec 28, 2009 at 16:23
  • What is even more strange is that MyCustomDialog is located in library that did not have fails during build for a very long time.
    – ironic
    Dec 28, 2009 at 16:27
  • 1
    Try cleaning and rebuilding the solution, it always used to fix that issue when I had it.
    – Rory
    Dec 28, 2009 at 16:31
  • No success. The simplest solution so far is to change base type of form to Form and then back.
    – ironic
    Dec 28, 2009 at 20:43
  • 2
    Finally the exact reason was found. Our project is under Source Safe, so typically all files are read only. When Visual Studio (VS) compiles the project it somehow analyzes, which files represent forms and therefore should be opened with Forms Designer. To indicate it for itself VS adds some tag in the .csproj file. BUT if the .csproj file is read-only (as it was in my case), VS cannot modify it, and solution browser still does not knows it is a form. The solution is to make .csproj file not read-only and rebuild everything.
    – ironic
    Jun 10, 2010 at 8:57
1

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

0

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.

0

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

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.