Windows form has disappeared in Visual Studio form designer
Asked Answered
P

12

6

Yesterday I edited a form in Visual Studio's form designer. When I returned to it today, the designer shows nothing. I can open the properties window, select all the different constituent components and edit their properties, but they do not show up. The application builds fine and the form can be run as usual.

I've tried a couple of different solutions, such as checking the .csproj file has the form.Designer.cs included, but nothing has worked.

Strangely, I did see this problem earlier in the week, but it fixed itself when I unlocked my computer after returning from a coffee break.

Any suggestions?

Plutonium answered 28/6, 2016 at 10:41 Comment(0)
W
4

I had similar issues in VS2019. I resolved it by using:

Window > Reset Window Layout.

Then double clicked on the Form in the Solution Explorer.

Prior to this, double clicking the form was having no effect.

Whacking answered 25/6, 2019 at 17:20 Comment(0)
R
4

I face a similar problem in Visual Studio 2019.

To help others who may have this issue. The problem is due to the class declaration in the Form1.cs file. Please ensure public partial class Form1: Form class is the first-class declared in the file. No other class declaration should be on top of this.

As described in this answer: https://mcmap.net/q/512437/-unable-to-get-the-designer-view-window-back-using-windows-forms-with-visual-studio-2010

Thanks, Sankar

Rhona answered 28/10, 2021 at 16:55 Comment(0)
S
3

There are actually a few reasons that one might encounter this issue. At times, it can be due a problem within the VS IDE and the way it incorrectly manages file types and subtypes. It normally does a great job with this "automagically", but it can also make painful and unexpected mistakes.

If you right-mouse-click (RMC) your Project, and unload it (not your solution) you will be able to RMC it again and choose "Edit Project File". Once there, search for your Form name. In my case, I will search for Form1.cs, note the incorrect icon I saw in the Solution Explorer View, and the code describing my form, within the project file:

Windows Form With Incorrect Icon-Subtype

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

Change this declarative statement to the following, adding the "Form" subtype:

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

Save your project file, then RMC on your project name in the Solution Explorer, choose "Reload Project", and you will see the correct icon as expected, and once again be able to use the form in Design mode:

Windows Form With Correct Icon-Subtype

*Note: This issue shouldn't occur with default forms (named Form1, Form2, etc) and even in my case, it happened with a form I named other than the default form name. I used that name in this example, purely for illustrative purposes.

Hopefully, this helps someone.

Wishing you all the best!

Straticulate answered 13/7, 2022 at 4:27 Comment(0)
P
2

Weird, after trying for an hour I ended up solving the issue 30 seconds after posting this!

I edited the size property of an item on the form using the properties tab, saved the form, and then reverted the form.cs, form.designer.cs, and form.resx files to the latest source control version.

At this point the form jollily re-appeared.

Edit: FWIW, this didn't work with another form which was exhibiting the same problem.

Edit 2: That other form has now fixed itself after coming back from lunch and unlocking my PC... Might be something to do with how that affects the display - everything shifts over to my right hand monitor when I do that.

Edit 3: OK, now it seems that modifying my display DPI fixes it. On Windows 10 go to System Settings -> Display, and then move the "Change the size of text: 100%" option to say 200%. Once this changes on screen, move it back to 100%.

This seems quite foolproof, although you sometimes have to jimmy it around a lot before it finally works. I know it has worked when I get both a vertical and horizontal scrollbar; the form is then further down the page.

Plutonium answered 28/6, 2016 at 10:45 Comment(1)
This worked for me to get most of the elements back, but I still need to manually re-add tabs for the tab control in the designer. Would be interested to know if there's a permanent fix for this.Krugersdorp
H
2

Just go to Form1.cs (Form1 is the name of your form), if you are able to see your source code then press Shift + F7. The form will show up.

Henricks answered 9/5, 2018 at 6:59 Comment(0)
P
2

I had the same problem.

My solution was to remove and add again the System.Windows.Forms reference.

Praedial answered 4/11, 2021 at 6:42 Comment(1)
Two years later, this was my fix as well. Super irritating, but thanks for commenting!Ulland
P
1

I also had a similar issue in VS2019.

My form [Design] was listed in the solution explorer but the code was not listed as a sub-item of that form.

I could access the code by right-clicking on the form in the solution explorer and choosing view code.

What seemed to solve the problem was to close down VS2019 and simply re-open it up.

Potty answered 10/2, 2020 at 15:7 Comment(0)
A
1

A Message appeared (with Errors and Warnings) for me which said that the first mentioned class in a cs code file must be the form class. I shifted my form class to the top of the files and everything was fine.

Alectryomancy answered 17/7, 2020 at 6:44 Comment(0)
C
0

I hadn't changed anything that would have broken my form, yet it still wouldn't load when I tried view designer. Restarted VS2019 and it worked after that. Give that a go before you try anything else!

Chrysarobin answered 4/9, 2021 at 9:37 Comment(0)
H
0

It happened to me too, and the solution was none of the proposed ones.

It seems that Visual Studio will only recognize an object file as a form object if the very first class declaration in the file is public partial class <FormName> : Form. If you declare any other class before the form in the same file, VS will cease to recognize it, replace the icon with an ordinary object class' icon, and won't show the Designer any more. Moving the class to the end of the file, after the form object solves the problem.

Hilton answered 15/3 at 16:17 Comment(0)
F
0

You can always do the old divide-and-conquer trick. Go into InitializeComponent() and comment out code until you figure out which control is the offending control.

Fogel answered 20/4 at 19:49 Comment(0)
L
-1

Go to Tools > Options > Environment > Preview Features and select the Use the preview Windows Forms designer ...

Then restart

Leonidaleonidas answered 28/10, 2022 at 10:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.