先前在C#中设计的Form界面,后来再打开时界面中的控件都不显示了,运行时跟设计时都不显示,哪位高手指点一下,谢谢
C#中Form窗口中的控件不显示
最新推荐文章于 2023-10-27 16:55:22 发布
本文解决了一个常见的C#编程问题——Form界面中的控件在设计时和运行时均不显示。提供了多种可能的原因及解决方法,包括检查控件可见性、构造函数中的InitializeComponent调用、控件层次问题等。
1450







原来是VS平台自我维护保存的问题 LZ 千万不要因为没出现关闭的时候保存
反正出现问你是否保存一定不能保存的 否则很惨只能重做界面了··
我以前也碰到过,就是不小心把InitializeComponent()那句给删掉了.
再删除项目下面的 *.vshost.exe 文件
再开项目就行了
看看这个有没有在构造函数里.
应该是这个问题了.
或者看看构造函数里的InitializeComponent()在不在
2.在InitializeComponent()函数里找到from的构造位置,如下所示
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(286, 294);
this.Controls.Add(this.cbxType);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.btnClear);
this.Controls.Add(this.lblResult);
this.Controls.Add(this.lbxList);
this.Controls.Add(this.btnOk);
this.Controls.Add(this.label2);
this.Controls.Add(this.txtNum);
this.Controls.Add(this.label1);
this.Controls.Add(this.txtPrice);
this.Name = "Form1";
this.Text = "商场收银系统";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
this.PerformLayout();
检查 是否有 this.Controls.Add(this.控件名); 基本可以解决问题,一点经验,望能共勉
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}