Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Form1.cs [Design] disappeared

Tags:

c#

winforms

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.

like image 374
Birdman Avatar asked Oct 18 '25 17:10

Birdman


2 Answers

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.

like image 60
Birdman Avatar answered Oct 21 '25 06:10

Birdman


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

like image 36
Marko Juvančič Avatar answered Oct 21 '25 08:10

Marko Juvančič



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!