HRC
HRC

Reputation: 171

Visual studio 2019 windows forms designer

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

Upvotes: 15

Views: 21348

Answers (9)

Evert
Evert

Reputation: 21

The solution I came up with and that worked for me;

  • Create a new project of the same type in the same solution.
  • Copy all afflicted forms from the troubled project to the new project.
  • Remove the afflicted forms from the troubled project.
  • Copy the forms back from the new project to the troubled project.

In short: Copy the afflicted forms to a new project and back.

By the way, in my case it happened in VS 2022.

Upvotes: 0

Mou
Mou

Reputation: 155

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);     
            }
        }
    }
}

Upvotes: 0

Paul Gee
Paul Gee

Reputation: 201

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();
     }
}

Upvotes: 1

ΩmegaMan
ΩmegaMan

Reputation: 31596

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

Upvotes: 2

Andreas
Andreas

Reputation: 674

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

Upvotes: 2

Johnny Wu
Johnny Wu

Reputation: 1518

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.

Upvotes: 0

newbie
newbie

Reputation: 1217

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).

Upvotes: 0

Farhan
Farhan

Reputation: 2575

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.

Upvotes: -1

Related Questions