有类似的问题(唯一的区别是当我在调试模式下运行项目一两次时,控件是可见的,然后它们也消失了。)
我不得不手动重新添加在designer.cs 文件中丢失的代码。
这就是我的 initializeComponent() 方法被简化为:
private void InitializeComponent()
{
this.SuspendLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
我不得不重新添加每个组件代码块,一次一个,就像这个 - 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();
}
当然,我不知道调色板坐标需要是什么。所以,我在代码中为 x,y 输入了 10,10。然后切换到设计器视图。控件放置在左上角。在 Visual Studio 毁了我的夜晚之前,我使用设计器将它放回原处。
确保在 InitializeComponent() 方法之后找到对控件的引用:
#endregion
private System.Windows.Forms.ListBox listBox1;
另一个提示:如果您不知道 Designer.cs 类正在为您的特定控件寻找什么属性,只需从工具箱中创建一个新属性,然后返回代码查看 Visual Studio 自动生成的内容为该控件类型生成。
快乐的小径,和下一个小时吻别:)