Windows form controls disappeared

25,306

Solution 1

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

Solution 2

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

Solution 3

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

Solution 4

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

Solution 5

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)

Share:
25,306

Related videos on Youtube

Wedge
Author by

Wedge

Updated on November 05, 2021

Comments

  • Wedge
    Wedge over 2 years

    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?

    • user1703401
      user1703401 almost 10 years
      Your form is probably throwing an exception at design time, one that's getting swallowed somehow. Start another instance of Visual Studio and use Tools + Attach to Process to attach to the 1st instance. Debug + Exceptions, tick Thrown boxes so the debugger stops when the exception is thrown.
  • Zorgarath
    Zorgarath over 6 years
    I have no option to exclude the designer file on its own.
  • Christopher
    Christopher over 5 years
    Tried this myself - even added to source control - but couldn't do it. I also tried moving the Designer file out of the project folder and re-adding it... sadly didn't work. Good idea though.
  • Jack Griffin
    Jack Griffin over 4 years
    This happened to me today : ALL controls disappeared. I did what you suggested and that solved the problem (Visual Studio 2013 Community Edition).
  • Eda
    Eda over 3 years
    I have a similar problem but in my case only the control buttons (maximize, minimize and close) are disappearing when I change to another culture. I tried this solution but I did not see any code in the designer where these controls are being added.

Related