Warm tip: This article is reproduced from stackoverflow.com, please click
c# winforms

Form1.cs [Design] disappeared

发布于 2021-02-19 19:24:04

I think I goofed up and my WinForms designer is missing now. I noticed this in my Form1.Designer.cs file:

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>

I deleted one line from this file because I accidentally added an extra button. I deleted it from the GUI designer but the code still remained. So I just deleted it.

My application compiles and runs correctly. But after poking around in Visual Studio for 20 minutes now & Googling I can't seem to get Form1.cs [Design] file to come back.

Basically this file (pic taken from Google)

enter image description here

The Form1.cs [Design] displayed some sort of error but I closed the tab. Now I can't seem to even get the tab back to see the problem.

Questioner
Birdman
Viewed
0
2020-06-20 17:12

Posting this to help others who may have this issue. The problem was that I created a class within my Form1.cs file BEFORE my public partial class Form1 : Form class. As described in this answer: https://stackoverflow.com/a/40243490/8887398

A key indicator this might be your problem is if your form looks like this in your solution explorer: enter image description here

Notice the icon for Form1.cs looks like a regular C# file. This is how it should look if it's a form:

enter image description here

You can clearly see the difference in the icon. Simply making sure the public partial class Form1 : Form class was first in the file instantly brought back the ability for me to open the Form1.cs [Design] with a simple double click.