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?
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.
My setup:
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 :)
In VS 2017, if you exclude yourForm.Designer.cs from the solution, then re-add it again should fix the problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With