How to open form designer in Visual Studio?
Asked Answered
S

14

15

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

Spermatic answered 26/11, 2018 at 19:26 Comment(3)
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.Kalliekallista
Try right clicking the designer file and see if you can find the designer in the "Open With" option list.Caricaria
@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.Spermatic
B
10

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.

Biron answered 27/11, 2020 at 12:10 Comment(3)
Good catch. Really pisses me off that this is a thing...Barner
Also valid for VS 2022. Thanks!Ellette
It works. 牛逼 to you!Antechoir
H
9

You are in the Folder view.

Change to the Solution (Project) view.

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

Housebreaker answered 26/11, 2018 at 19:35 Comment(5)
How do I switch between the two?Spermatic
do you have solution file there, just click on it. If you don't have .sln, the press on .csprojHousebreaker
When clicking on the icon, it says that there is no solution found. There is no .sln file in the explorer, though there is a .csproj file. Clicking on that does not yield any different results.Spermatic
close VS and click on project file from Windows ExplorerHousebreaker
or from VS: File -> Open -> Project/SolutionHousebreaker
R
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.

Resonance answered 26/11, 2018 at 19:33 Comment(1)
this made the form design view appear for me, but then I couldn't compile. Something about 'duplicate compile items...'Costin
H
3

There is a very simple solution in Visual Studio 2022. If the design view of say form1 is not open, go into the Form1.cs and find the "InitializeComponent();" (see the picture). You can either right click on it, a drop down list will appear, select "View Designer". You could also just place the mouse over the line and press the keys "Shift" and "F7" at the same time. Either way, the design view will open.enter image description here

Hypsometry answered 3/3 at 14:37 Comment(0)
L
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.

Laryngoscope answered 30/1, 2020 at 18:53 Comment(0)
C
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

Camion answered 26/11, 2018 at 19:39 Comment(4)
@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 fileCamion
That did not fix the problem, though I will attempt that solution again when I can.Spermatic
what i mean to say is close visual studio and double click the project file, in your case it is UserInterface.csproj file.Camion
Open the project from the Explorer. Check the added imageCamion
I
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

Isahella answered 22/9, 2021 at 20:23 Comment(0)
C
1

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>
Clem answered 26/1, 2022 at 5:58 Comment(0)
N
1

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

Neville answered 31/5, 2022 at 3:4 Comment(0)
Z
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.

Zacharyzacherie answered 1/2, 2020 at 17:37 Comment(0)
J
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.

Joslin answered 1/9, 2021 at 10:56 Comment(0)
G
0

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

Granulite answered 17/2, 2022 at 13:48 Comment(0)
M
0

I Solved this issue, by updating the project to use a newer version of Dot Net. From Dot Net 6 to 8.

HTH

Monophonic answered 22/8 at 11:46 Comment(0)
I
-1

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.

Impoverished answered 3/6, 2022 at 13:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.