Monday, April 16

Visual Studio 2005 - Disappearing controls on Windows Form

My computer crashed the other day and when I returned to edit my application, to my horror I noticed that the controls on a very complicated windows form that I was working on had vanished. When I tried to edit it, all I got was an empty dialog box, but all the source code for my form was still there.

I found several references to disappearing controls in VS2003, but they all said the problem had been fixed in VS2005.

The cause of this turned out to be that some lines had removed themselves from the designer.cs file :-


///
/// formMyForm
///
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.ClientSize = new System.Drawing.Size(869, 717);
this.Controls.Add(this.splitContainer1);
this.Controls.Add(this.buttonOK);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonAccept);
this.Name = "formMyForm";
this.Text = "My form title";




Copying these lines from the version in source control seemed to restore all the controls in the dialog.