9

I am attempting to create a Windows Forms app in C# in Visual Studio.

Normally one can double click the Form1.cs file in the Solution Explorer in order to access the simple drag and drop designer.

Unfortunately, it only opens up the code for the file.

solution explorer

Jimi
  • 29,621
  • 8
  • 43
  • 61
SwingingChad
  • 101
  • 1
  • 1
  • 6
  • Probably there was some error when creating the project or you selected and incorrect type of project. Try by clicking "Add New Item" and choose a new Windows Form element. Probably you would need to change the startup class under Program.cs for the program to launch. – Mauro Bilotti Nov 26 '18 at 19:32
  • 2
    Try right clicking the designer file and see if you can find the designer in the "Open With" option list. – Sweeper Nov 26 '18 at 19:32
  • @ThomasWeller If that is the case, then it would probably be easier to recreate the original project, as little has been done thus far. I will do that, and update if issues persist. – SwingingChad Nov 26 '18 at 19:42

12 Answers12

6

Have the same issue when placing another class before the form class (in this case my ImageContainer class).

namespace ImageProcessor
{
    internal class ImageContainer
    {
    }
    
    public partial class Form1 : Form
    {
        private ImageContainer m_img = null;
    }
}

By just moving the internal class ImageContainer after the public partial class Form1 : Form { } the VS2019 drag&drop designer could load my Form1 class.

namespace ImageProcessor
{
    public partial class Form1 : Form
    {
        private ImageContainer m_img = null;
    }

    internal class ImageContainer
    {
    }
}

Also symbol in Solution Explorer changed back to a dialog icon.

wlasar86
  • 115
  • 2
  • 9
5

You are in the Folder view.

Change to the Solution (Project) view.

This icon enter image description here at the top of Solution Explorer.

Alexan
  • 8,165
  • 14
  • 74
  • 101
3

The associations between the files must have gotten broken somehow. You can manually edit the .csproj file and correct it. Search for Form1. You should have entries for each file that look something like this:

<Compile Include="Form1.cs">
  <SubType>Form</SubType>
</Compile>
<Compile Include="Form1.Designer.cs">
  <DependentUpon>Form1.cs</DependentUpon>
</Compile>
<EmbeddedResource Include="Form1.resx">
  <DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>

Notice the SubType and DependentUpon. Those are the important pieces.

Gabriel Luci
  • 38,328
  • 4
  • 55
  • 84
  • this made the form design view appear for me, but then I couldn't compile. Something about 'duplicate compile items...' – john k Mar 18 '23 at 21:06
2

In my case right-click on Form1.cs (with correct Form icon) and select "View Designer" still showing code.

I found this thread and realized I accidentally choose .Net Core instead of .NET Framework when creating new project:

enter image description here

I should able see this long xml inside .csproj file (.NET Framework) of Solution Explorer panel, which the TargetFrameworkVersion showing v<Number>:

... 
<OutputType>WinExe</OutputType>
<RootNamespace>HelloWorld</RootNamespace>
<AssemblyName>HelloWorld</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
...

, instead of short xml below (*.Net Core), which the TargetFramework showing netcoreapp<Number>:

<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">

  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <UseWindowsForms>true</UseWindowsForms>
  </PropertyGroup>

</Project>

To check project type, can refer this answer.

Microsoft devlogs stated that Designer with .Net Core is not shipped by default yet:

If you want to work with .NET Core project, don’t forget to install the .NET Core Windows Forms Designer, since it isn’t yet shipped inside Visual Studio by default. See the previous “Enabling the designer” section.

林果皞
  • 7,539
  • 3
  • 55
  • 70
1

Click on the highlighted icon in the below image. It is the Solutions and Folders Icon which will take you back to solution view.

enter image description here

enter image description here

Sats
  • 1,913
  • 1
  • 15
  • 21
  • @ColinG , from what i can tell from your image, is that the solution file is not existing. The Solutions and Folders is not able to locate the solution. For now close the Visual Studio and open it by clicking on the Project and once the Visual studio is open click save. It will again create Solution file – Sats Nov 26 '18 at 19:57
  • That did not fix the problem, though I will attempt that solution again when I can. – SwingingChad Nov 26 '18 at 20:11
  • what i mean to say is close visual studio and double click the project file, in your case it is UserInterface.csproj file. – Sats Nov 26 '18 at 20:13
  • Open the project from the Explorer. Check the added image – Sats Nov 26 '18 at 20:16
1

Somehow the .resx file got corrupted, i fixed that by copying this same file from my other form. Just delete the corrupt one, paste it, and change the name

0

In VS2019 just delete the first project and recreate another one. It will fix the problem of viewing designer page. Now you are able to view your designer.

Gaur 97
  • 73
  • 5
0

Found this solution somewhere else:

I've just had similar problem in Visual Studio 2017. On a "Form1.cs [Design]" there was an error shown and I closed it. Then I noticed Form1.cs had no "View Designer" option (also the icon changed to that of a regular class). Luckily, I figured out what the error was: I'd put a class other than public partial class Form1 as a first class in a Form1.cs file. Fixing that caused the icon to change and reenabled the "View Designer" option.

That's a pity those kind of errors doesn't show on the Error List. My error was easy to spot, but I see how this can be a problem, especially on bigger projects.

link: https://developercommunity.visualstudio.com/t/open-form-designer-from-solution-explorer/44160#:~:text=I%27ve%20just%20had,on%20bigger%20projects.

0

Another possibility is that your form class is missing a SubType subelement in its xml element in the csproj.

For example, here is one that does have the needed subelement:

<Compile Include="MainForm.cs">
  <SubType>Form</SubType>
</Compile>
Poul
  • 1
0

In my case the problem was an dot in the cs file name e.g.: "Form1.Core.cs"

Jens
  • 2,327
  • 25
  • 34
0

Right-click on Form1.cs
Select Open With option
From the Open With option, choose "CSharp Form Editor (Default) Click OK

Open With
Open With Options

0

Actually you are opening the design from the file . simply run the program and it will automatically open design form .just ignore if there are built in errors.