您的位置:首页 > 其它

叨叨一下vs2005 winform 窗体上所有控件突然消失的问题

2010-09-01 17:30 309 查看
症状:窗体关闭时或者窗体代码确定没有被自己主动修改或者丢失(比如剪切,删除)的状况下,再打开这个窗体发现窗体上所有控件全部消失,窗体变成初始化时大小,但后台逻辑代码都还在.

事件发生规律:无规律.........出现过好几次,新系统老系统都有

分析给解决办法:

在百度里搜索"vs2005 winform 所有控件突然消失"也会出现一些解决办法,但是没有符合我的这种情况的,但大家一致都认为在*.Designer.cs里的代码因为vs的bug出现了丢失现象,下面把我当时的代码贴出来(节选)

/// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{

this.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.系统维护ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.替换数据库ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItem2 = new System.Windows.Forms.ToolStripSeparator();
this.重新登录ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.退出系统ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.基础维护ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStrip1 = new System.Windows.Forms.ToolStrip();
this.toolStripButton1 = new System.Windows.Forms.ToolStripButton();
this.toolStripButton3 = new System.Windows.Forms.ToolStripButton();
this.toolStripButton2 = new System.Windows.Forms.ToolStripButton();
this.toolStripButton4 = new System.Windows.Forms.ToolStripButton();
this.menuStrip1.SuspendLayout();
this.toolStrip1.SuspendLayout();
this.SuspendLayout();
//
// menuStrip1
//
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.系统维护ToolStripMenuItem,
this.基础维护ToolStripMenuItem,
this.号码统计分析ToolStripMenuItem});
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(794, 24);
this.menuStrip1.TabIndex = 6;
this.menuStrip1.Text = "menuStrip1";

............

//
// toolStripButton4
//
this.toolStripButton4.ImageTransparentColor = System.Drawing.Color.Magenta;
this.toolStripButton4.Name = "toolStripButton4";
this.toolStripButton4.Size = new System.Drawing.Size(57, 57);
this.toolStripButton4.Text = "退出系统";
//
// Main
//
this.ClientSize = new System.Drawing.Size(292, 266);
this.Name = "Main";
this.Load += new System.EventHandler(this.Main_Load_1);
this.menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout();
this.toolStrip1.ResumeLayout(false);
this.toolStrip1.PerformLayout();
this.ResumeLayout(false);

}


先看Main里面的,很显然,少了很多代码,问题就出现在这了,下面是我修改了以后的代码

//
// Main
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.LightSteelBlue;
this.ClientSize = new System.Drawing.Size(944, 568);
this.Controls.Add(this.toolStrip1);
this.Controls.Add(this.menuStrip1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.IsMdiContainer = true;
this.MainMenuStrip = this.menuStrip1;
this.Name = "Main";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "LED电子屏施工配件单";
this.Load += new System.EventHandler(this.Main_Load);
this.menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout();
this.toolStrip1.ResumeLayout(false);
this.toolStrip1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();


比较一下,就发现以下代码没了

this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.LightSteelBlue;
this.Controls.Add(this.toolStrip1);
this.Controls.Add(this.menuStrip1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.IsMdiContainer = true;
this.MainMenuStrip = this.menuStrip1;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "LED电子屏施工配件单";

其实最重要的是这" this.Controls.Add(this.toolStrip1); this.Controls.Add(this.menuStrip1);"两句没了.

另外toolStripButton4里也少了一句"this.toolStripButton4.Click += new System.EventHandler(this.toolStripButton4_Click);",就是说控件的Click事件没了,挨个的给每个控件加Click事件也不是件轻松的事情............

总结:vs2005的bug...........

这段事件光做web开发了,没想到cs下还有这么多bug,以后慢慢整理吧
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐