Wedge
Wedge

Reputation: 141

Windows form controls disappeared

I have a windows forms project that seems to have lost all of its controls in the design view. When I run the project the controls appear as they should. Only the design view is broken in visual studio for this form, all other forms are the same.

I have tried reopening the solution and reopening the file to no avail. I have also tried cleaning and rebuilding the solution to no avail. I have made a video screen capture describing the problem

What should I try next?

Upvotes: 11

Views: 33572

Answers (9)

Mike K
Mike K

Reputation: 11

I had the exact same issue: the controls on my main form did not show anymore.

I closed the app and shutdown completely, rebooted and reopened VB 2022. The exact same form now shows all controls, and works as original! I did not change any code!

Upvotes: 0

Fred Smith
Fred Smith

Reputation: 2129

I have Visual Studio 2019 (version 16.11.5) on a Windows 10 (20H2) and I notice a bug since the last version upgrade on WinForm projects. I have a WinForm project (.NET 4.8 target) and I add several controls (buttons, labels and textboxes) and I start to add some code and I come back to Form1.Design tab and all controls disappear so my solution is to go back to the Form1.cs tab and then go back to the Form1.cs[Design] tab and all controls reappear magically. It looks like a refresh is missing in Visual Studio Design tab.

Upvotes: 0

Pranav G
Pranav G

Reputation: 61

What you might be looking for is 'toolbox'.

I was lost looking for it for so long. Just a simple Ctrl+Alt+X brings it back.

Upvotes: 6

Mike
Mike

Reputation: 807

Looks more like another form is being invoked in runetime.

You should have captured the code to understand the application's behaviour (like the form code and program.cs code).

Upvotes: 2

Christopher
Christopher

Reputation: 2256

Wow how annoying! This drove me nuts so I wasted 45 minutes trying to fix it w/out having to re-add the control which would be super annoying (plus this is the 3rd or 4th time this has happened to me in VS 2017 in last few weeks).

For me the solution was to find my control in the Designer file (via "Go To Implementation"). I found out then that the ".Add" line for that control was simply gone? After I manually added it back myself and saved it magically re-appeared in my Windows Form Design view. Screenshot below for reference.

enter image description here

My setup:

  • Windows 7 x64
  • Visual Studio 2017 Pro x64
  • Windows C# Forms project
  • Missing controls (most of time) have been inside a panel object

Upvotes: 9

David L
David L

Reputation: 723

In VS 2017, if you exclude yourForm.Designer.cs from the solution, then re-add it again should fix the problem.

Upvotes: 1

Lazy Babe
Lazy Babe

Reputation: 112

Had similar problem (only difference was that the controls were visible when I ran the project in debug mode one or two more times, then they were gone there, too.)

I had to manually re-add code that was lost in the designer.cs file.

This is what my initializeComponent() method had been reduced to:

    private void InitializeComponent()
    {
        this.SuspendLayout();

        this.ResumeLayout(false);
        this.PerformLayout();
    }

I had to re-add each component code chunk, one at a time, like this one - listBox1:

private void InitializeComponent()
    {
        this.listBox1 = new System.Windows.Forms.ListBox();
        this.SuspendLayout();

        // 
        // listBox1
        // 
        this.listBox1.FormattingEnabled = true;
        this.listBox1.Location = new System.Drawing.Point(10, 10);
        this.listBox1.Name = "listBox1";
        this.listBox1.Size = new System.Drawing.Size(133, 43);
        this.listBox1.TabIndex = 5;

        // 
        // Form1
        // 
        this.ClientSize = new System.Drawing.Size(550, 430);
        this.Controls.Add(this.listBox1);

        this.Name = "Form1";
        this.Load += new System.EventHandler(this.Form1_Load);
        this.ResumeLayout(false);
        this.PerformLayout();

    }

Of course, I had no idea what the palette coordinates needed to be. So, I put 10,10 for x,y, in the code. Then switched to the designer view. The control was placed at the top left. I used the designer to put it back where I had it in the first place before Visual Studio wrecked my night.

Make sure you find a reference to your control after the InitializeComponent() method:

    #endregion
    private System.Windows.Forms.ListBox listBox1;

One more tip: if you have no idea what properties that the designer.cs class is looking for for your particular control, just make a new one from the toolbox, and go back to the code to see what Visual Studio auto-generates for that control type.

Happy trails, and kiss the next hour goodbye :)

Upvotes: 2

vscott
vscott

Reputation: 1

Check and see if the problem is that the designer.cs in not nested correctly. It must be under the .cs file. If not, right-click and 'Exclude From Project' all files associated with the Form, then re-add the Form (.cs) back into the project. This will solve the issue.

Upvotes: 0

becike
becike

Reputation: 365

Probably you referenced some usercontrol defined in teh same solution, but in different project, what changed, and must be solved by s simple Solution/Rebuild All. If not, then it could be a build issue (mixed x86 and x64 builds)

Upvotes: 1

Related Questions