Reputation: 511
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?
Upvotes: 6
Views: 27751
Reputation: 1183
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.
Upvotes: 0
Reputation: 2262
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.
Upvotes: 0
Reputation: 1652
Go to Tools > Options > Environment > Preview Features and select the Use the preview Windows Forms designer ...
Then restart
Upvotes: -1
Reputation: 131
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:
<...>
<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:
*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!
Upvotes: 3
Reputation: 21
I had the same problem.
My solution was to remove and add again the System.Windows.Forms
reference.
Upvotes: 2
Reputation: 49
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://stackoverflow.com/a/40243490/8887398
Thanks, Sankar
Upvotes: 4
Reputation: 331
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!
Upvotes: 0
Reputation: 41
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.
Upvotes: 1
Reputation: 341
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.
Upvotes: 1
Reputation: 8904
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.
Upvotes: 4
Reputation: 769
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.
Upvotes: 2
Reputation: 511
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.
Upvotes: 2