Birdman
Birdman

Reputation: 1524

Form1.cs [Design] disappeared

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.

Upvotes: 4

Views: 18496

Answers (3)

Muzamal Sheikh
Muzamal Sheikh

Reputation: 1

  1. close visual studio 2022 (or whatever version)
  2. open project using from whatever folder you are using if you haven't already
  3. scroll over to "solution explorer" (this is located on the right side of the visual studio interface menu) this is the file structure: this is my files structure
  1. then double-click on music-database-app-sql.sln, obv your file structure will be different--> new interface will show
  2. now right click on form1.cs
  3. click View Designer
  4. done! now you can mod the interface all you want

Upvotes: 0

Marko Juvančič
Marko Juvančič

Reputation: 5890

I'll use this post to show my solution. I have a solution with 30 projects, 5 of them are WinForms apps. Everything being equal - it was possible to design forms in four of those, only one was "code only".

What worked for me was:

  • go to the properties of the problematic project
  • change the output type to "Console application"
  • save
  • change the output type back to "Windows application"
  • save

Change output type

Upvotes: 2

Birdman
Birdman

Reputation: 1524

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.

Upvotes: 17

Related Questions