4

As per How do I open a Visual Studio project in design view?, Shift + F7 or F7 should show the design view, but i only get the code view.

Double clicking on Form.cs doesn't help either as mentioned in https://msdn.microsoft.com/en-us/library/w5yd62ts(v=vs.100).aspx.

Right clicking on Form1.cs does not display an option allowing me to open the design view

How can i open the design view? Options i get on right clicking Form1.cs

Romano Zumbé
  • 7,893
  • 4
  • 33
  • 55
Sam Wrayn
  • 63
  • 1
  • 1
  • 7

9 Answers9

20

Check your Form1.Designer.cs and Form1.cs files to make sure you haven't put another class in at the top of the file before your partial class Form1{ because the designer will only load if the Form class is the first class defined in the file.

You mentioned this solution as a comment to one of the answers but I tried performing the edits on the .csproj first before realizing that my changes were being reverted and I needed to remove the myCustomPropertyView class I'd lazily added to the top of the file.

Visual Studio was still acting a bit weird (telling me I had errors on lines which were fully commented out) but once I closed and re-opened Visual Studio I was back up and running.

nvuono
  • 3,323
  • 26
  • 27
  • Yep. It's alluring to add a little helper class on top of "partial class Form1{" -- just put it on the bottom instead... – John Silence Dec 07 '18 at 13:26
  • Just as the error message in the form editor said when you try to open Form1.cs for the first time after violating the rules. After this you can never open it in the form editor and see the error message. – jw_ May 03 '19 at 02:37
  • God, thank you for this! I couldn't figure out why designer disappeared. And thanks to your comment now I know that I can't put another class before Form1. Thanks! – Elizabeth Grant Dec 13 '21 at 18:12
12

Try this:

1) Right Click on Solution Explorer.

2) Go to the file that does not have Designer View.

3) Exclude It From Project.

4) Include It From Project.

It worked for me

EduardoUstarez
  • 603
  • 11
  • 22
4

I think this will be a problem with your project file (.csproj). If you open it in a text editor it is just an XML file that can (but in most cases shouldn't) be edited. There are multiple <ItemGroup> nodes. One has a sub node that (possibly) looks like this:

<Compile Include="Form1.cs" />

Replace it with:

<Compile Include="Form1.cs">
  <SubType>Form</SubType>
</Compile>

EDIT:

There should also be these two nodes:

<Compile Include="Form1.Designer.cs">
  <DependentUpon>Form1.cs</DependentUpon>
</Compile>

<EmbeddedResource Include="Form1.resx">
  <DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>
Romano Zumbé
  • 7,893
  • 4
  • 33
  • 55
  • I followed these steps, but it still doesn't show the design view. When i went back to the csproj file after checking for design view, the code had reverted back to only from the edit that you had suggested – Sam Wrayn Jun 22 '17 at 16:08
  • 2
    Turns out that the error was `The class Form1 can be designed, but is not the first class in the file...` I hadn't read this the first time and ended up on a wild goose chase. Thanks for all the help! – Sam Wrayn Jun 22 '17 at 16:45
  • Just as I asked in my second comment ;-) – Romano Zumbé Jun 22 '17 at 17:10
  • This doesn't work, as Sam Wrayn said, it turns back to the previous form. The right answer is to ensure Forms1 is the first class in the source file. – jw_ May 03 '19 at 02:34
  • But this answer is the way to bring back your project to the state before you try to open the problem form and you can see the error message if you miss it before. – jw_ May 03 '19 at 02:41
2

Recently, a Windows Forms was released that works with .Net Core 3.0

The Designer for that form isn't included in the Visual Studio bundle. So if you want to open the designer for the .Net Core version of windows forms, you need to install a VSIX extension before it is possible. You can download the extension here: https://aka.ms/winforms-designer

I don't know if this extension works specifically with vs15, so if you can't install it, try using a winforms version that isn't the .Net Core one.

source of my info: https://devblogs.microsoft.com/dotnet/introducing-net-core-windows-forms-designer-preview-1/

vbergaaa
  • 21
  • 1
1

Try restarting Visual Studio, rebuilding solution, and running it

foyss
  • 973
  • 2
  • 8
  • 24
0

I had the same problem and solved it by creating a new project, but this time a .NetFrameWork application instead of .NetCore. Then when I opened the new project, I got the designer view immediately (as expected) with the new Form1 in it...;-)

So I guess the problem was chosing the wrong template when creating the application...

I hope this helps... John

Johan
  • 11
  • 1
0
  1. First, create a new form in the same directory.
  2. Exclude 2 forms from the project (NEWFORM and FORMERR)
  3. Then Open Folder in File Explorer
  4. Swap name FORMERR -> NEWFORM and vice versa
  5. Finally, Include NEWFORM (FORMERR with Name NEWFORM) => Sorry I'm not good at English.
Thanh IT
  • 1
  • 1
0

In my case it was because I had declared a helper class (for the dialog result) and put this declaration at the top of the form .cs file. Clearly this confuses Visual Studio because it expects the form class to be the first thing it finds in the file. This seems rather silly to me, since surely it can just search down the file...

Moving the helper class declaration to after the form class, made Visual Studio restore the form icon for the .cs file in the Solution Explorer and show the View Designer option in the right click menu

-2

Tools -> Import and export settings -> Reset all settings -> Try Shift + F7 again

Peter
  • 76
  • 7