Reputation: 103
When I create a new Windows Desktop Form Application using .NET Core with the latest Visual Studio 2019 Community Edition update, I cannot view the design view of the form, i.e., Form1.cs[Design]. When I click on the appropriately labeled Form1.cs file, it only opens up the code view.
New Solution Open Form1.cs code view only
Upvotes: 9
Views: 13844
Reputation: 617
I opened the project in explorer and deleted the entire .vs folder. Then, I reopened the project in visual studio and it worked again.
Upvotes: 0
Reputation: 21
I had another class declared in my Form1.cs file, and its declaration was before the Form1 class declaration. I moved that other class after the Form1 declaration, and then I got it working again.
Upvotes: 2
Reputation: 11
It could simply be that within your [some_form_name].cs file the line:
public partial class [some_form_name] : Form
was deleted from the namespace during your editing. This line should be just below the namespace declaration.
A good indication of this would be that your [some_form_name].cs
file will have a "C#" symbol in front of it instead of the form symbol in the Solution Explorer.
Upvotes: 1
Reputation: 11
What works for me is to create a new form into the project. In my case this somehow makes the designer work again, and after that the existing forms will also open without issue for the rest of the session.
Edit: I got a notification that this answer is unclear. Create a new form, then delete it. I don't know what's unclear about this.
Upvotes: 0
Reputation: 13106
I just ran into this and the problem was caused by code in the constructor that was calling code that normally access resources unavailable at design time.
I have a helper function I use to test for design time:
// Constructor
public MyForm()
{
InitializeComponent();
if (DesignTimeChecker.IsInDesignMode()) return; //<-- added to my form
// Rest of stuff that shouldn't be there
// ...
}
Once this code was added to the form's constructor, the Form icon magically appeared and I could open the form in the designer. So basically, check if it is design time (correctly, it can be a pain) and don't run "runtime" type code in the constructor.
Note: I just noticed this was for .NET Core but my example is in .net framework project (4.8). Mileage may vary.
Upvotes: 0
Reputation: 203
I found this trick worked for me:
Right click your project in Solution Explorer and select 'Unload Project' from the context menu (near the bottom). Right click again and select 'Load Project'
Now when you double click on your form class, it opens in the design editor
Upvotes: 8
Reputation: 65
This thread is the first when requesting "c# visual studio 2019 cannot open designer", so the solution may be useful for those who have encountered an error when the WinForms constructor stopped opening in VS2019. The screenshot shows the steps to DISPLAY the ERROR that caused WinForm to stop displaying
Upvotes: -1
Reputation: 9926
Apparently, according to this page, you can bring up form designer in the following mysterious steps:
<>
Why this?... I literally have zero idea. But it worked for me. Maybe tomorrow I'll find out more about this and yes I promise to come back and update - until then, just follow this little yellow brick road. I hate the fact that in 2021 some of the modern tools require dark sorcery to operate on a basic level, but hey. We're in this together.
Good luck!
Upvotes: 0
Reputation: 9475
Edit: At the time the question was asked Microsoft hadn't released the visual designer for WinForms in .NET Core in Visual Studio 2019. It needed a separate preview install. By May 2020, Visual Studio version 16.6, the designer was still in preview but could be enabled from Tools/Options/Environment/Preview Features/'Use the preview Window Forms designer for .NET Core apps' without needing an install.
As of November 2020 the designer is still in preview, but is enabled by default in projects in Visual Studio 2019 version 16.8 and later. It's still not complete, particularly re data binding, but the number of issues is much smaller. It can now be disabled via the Tools/Options menu as discussed above.
Upvotes: 6