叨叨一下vs2005 winform 窗体上所有控件突然消失的问题
2010-09-01 17:30
309 查看
症状:窗体关闭时或者窗体代码确定没有被自己主动修改或者丢失(比如剪切,删除)的状况下,再打开这个窗体发现窗体上所有控件全部消失,窗体变成初始化时大小,但后台逻辑代码都还在.
事件发生规律:无规律.........出现过好几次,新系统老系统都有
分析给解决办法:
在百度里搜索"vs2005 winform 所有控件突然消失"也会出现一些解决办法,但是没有符合我的这种情况的,但大家一致都认为在*.Designer.cs里的代码因为vs的bug出现了丢失现象,下面把我当时的代码贴出来(节选)
先看Main里面的,很显然,少了很多代码,问题就出现在这了,下面是我修改了以后的代码
比较一下,就发现以下代码没了
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,以后慢慢整理吧
事件发生规律:无规律.........出现过好几次,新系统老系统都有
分析给解决办法:
在百度里搜索"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,以后慢慢整理吧
相关文章推荐
- 关于vs2005,Winform窗体中的控件突然消失解决方法
- wpf用户控件 弹出窗口因主窗体最小化而消失的问题
- 对于C#中,窗体中设计好的控件,突然不见了问题的解决
- C# winform上面的控件突然全部消失
- s2013 winform窗体打包的问题和lable控件的问题
- winform窗体上的所有控件都不显示
- winform 利用 多线程 处理窗体假死,利用 Invoke BeginInvoke 处理子线程调用 UI 控件报错的问题
- 关于c#窗体控件突然消失的解决办法
- winform 遍历窗体中所有用户控件中的textbox 然后赋为空值
- WinForm遍历窗体所有子控件的方法
- 解决VS2005在Winform窗体设计界面中数据源窗口灰化不显示数据源的问题
- winform中如何获得窗体中所有的控件
- c#中跨线程调用windows窗体控件 .我们在做winform应用的时候,大部分情况下都会碰到使用多线程控制界面上控件信息的问题。然而我们并不能用传统方法来做这个问题,下面我将详细的介绍。
- C# WinForm窗体中有控件时keyDown事件问题处理方式
- c#WinForm下窗体权限设计(遍历菜单下的所有菜单及所有form、form中的控件)
- 遍历winform窗体上的所有控件(包括DevExpress.XtraEditors控件)且对其做相应的处理
- winform继承窗体,无法修改父窗体控件问题处理笔记
- C#中继承窗体会导致控件消失的问题解决
- Winform窗体控件图片过多后卡顿问题
- 解决vtkWindowForm控件突然消失问题:动态加载vtkWindowForm