Visual studio 2019 windows forms designer

Viewed 19896

I'm having a problem with the windows form application . When I create the windows form application , it displays the source code for the form but not the designer layout

8 Answers

I had the same problem. The following steps helped me

  1. Remove any other classes than the Form class in the yourformname.cs file
  2. Unload the project and right click on the project and choose edit project
  3. Make sure yourformname form has the SubType set to form <SubType>Form</SubType> and save the file
  4. Reload the project

As of version 16.8.0 Preview 2.1 I have found that I have to turn off this setting and restart and add my form. Once added, I can turn it back on, restart and work.

enter image description here

This happened to me as well.

I was using the wrong template (.net core when I wanted to use the full .net framework which allows you to edit the form as you were used to in vs 2017 or previous versions).

I am using 16.6.5 and it appears after you first created the project, you have to run the project in order for IDE to pickup the form.cs.

Certainly in WinForms one thing to check is you haven't declared any other classes in the form class file before the form itself. The example below will prevent the designer loading the form or even giving you the menu option to 'View Designer'

// Don't do declare a class here
public class MyNewClass
{
}

public partial class MyForm: Form
{
    public MyForm()
    {
        InitializeComponent();
     }
}

Removing inner class makes my form back to Visual Studio Design display.

For example, this Form2 will be regarded as normal class if you uncomment its inner class.

namespace XXX {
    //public class EventMsgXXX:EventArgs {
    //   public string mmm {get; private set;}

    //   public EventMsgXXX(string str) {
    //      mmm = str;
    //   }
    //}

    public partial class Form2:Form {
        public event EventHandler<EventMsgXXX> OnCallback;

        public Form2() {
            InitializeComponent();
        }

        private void btn_Click(object sender,EventArgs e) {
            EventHandler<EventMsgXXX> handler = OnCallback;
            if (handler != null) {
                EventMsgXXX arg = new EventMsgXXX("HELLO");
                handler(this, arg);     
            }
        }
    }
}

I have tried the suggestion by Danielle, but it appears to be a circular reference to other articles Olia. A plethora of comments also say that what Olia is suggesting, does not work, and at the end, you need to do the following.

Solution

Download Visual Studio 16.6.0 Preview 2.1 from here. This works.

Related