C# 窗体 切换、重复显示等遗留问题解决(第五天)

一、解决同一窗体多次点击重复显示BUG

(1)点击弹出学校窗体

 1         #region 弹出学校窗体               
 2         /// <summary>
 3         /// 弹出学校窗体
 4         /// </summary>
 5         /// <param name="sender"></param>
 6         /// <param name="e"></param>
 7         private void SchoolToolStripMenuItem_Click(object sender, EventArgs e)
 8         {
 9             //点击后显示SchoolTan这个弹窗
10             SchoolTan schooltanchuang=new SchoolTan();
11                    
12             //this.IsMdiContainer = true;
13             //WFromMain mainForm = new WFromMain();
14             //schooltanchuang.MdiParent = this;
15             /*
16              *  方法:明确父子关系:
17                     son form = new Form();
18                     form.MdiParent = this(father);
19                     form.show();
20                     前提是先要设置father窗体
21                     isMdiContainer = true; 
22              * **/
23             if (this.MdiChildren==null||this.MdiChildren.Length==0)
24             {
25                 schooltanchuang.Show();
26                 //让子窗体不超出父窗体界限,给子窗体指定父窗体
27                 schooltanchuang.MdiParent = this;
28                 return;
29             }
30             bool flag = false;
31             foreach (var item in this.MdiChildren)
32             {
33                 if (item.Text == schooltanchuang.Text)
34                 {
35                     schooltanchuang = item as SchoolTan;
36                     schooltanchuang.Activate();
37                     flag = true;
38                     break;
39                 }
40             }
41             if (!flag)
42             {
43                 schooltanchuang.Show();
44                 //给子窗体指定父窗体
45                 schooltanchuang.MdiParent = this;
46             }
47         }
48         #endregion
View Code

(2)弹出商会组织窗体

 1  #region 弹出商会组织窗体               
 2         /// <summary>
 3         /// 弹出商会组织窗体
 4         /// </summary>
 5         /// <param name="sender"></param>
 6         /// <param name="e"></param>
 7         private void ShanghuiToolStripMenuItem_Click(object sender, EventArgs e)
 8         {
 9             //点击弹出重庆商会窗体
10             ShangHui shang = new ShangHui();
11             //shang.Show();
12             //shang.MdiParent = this;
13             if (this.MdiChildren == null || this.MdiChildren.Length == 0)
14             {
15                 shang.Show();
16                 //让子窗体不超出父窗体界限,给子窗体指定父窗体
17                 shang.MdiParent = this;
18                 return;
19             }
20             bool flag = false;
21             foreach (var item in this.MdiChildren)
22             {
23                 if (item.Text == shang.Text)
24                 {
25                     shang = item as ShangHui;
26                     shang.Activate();
27                     flag = true;
28                     break;
29                 }
30             }
31             if (!flag)
32             {
33                 shang.Show();
34                 //给子窗体指定父窗体
35                 shang.MdiParent = this;
36             }
37         }
38         #endregion
View Code

(3)点击弹出公益组织窗体

 1  #region 点击弹出公益组织窗体               
 2         /// <summary>
 3         /// 点击弹出公益组织窗体
 4         /// </summary>
 5         /// <param name="sender"></param>
 6         /// <param name="e"></param>
 7         private void 公益组织ToolStripMenuItem_Click(object sender, EventArgs e)
 8         {
 9             //点击弹出公益组织窗体
10             GongYi gongyi = new GongYi();
11             //gongyi.Show();
12             //gongyi.MdiParent = this;
13             if (this.MdiChildren == null || this.MdiChildren.Length == 0)
14             {
15                 gongyi.Show();
16                 //让子窗体不超出父窗体界限,给子窗体指定父窗体
17                 gongyi.MdiParent = this;
18                 return;
19             }
20             bool flag = false;
21             foreach (var item in this.MdiChildren)
22             {
23                 if (item.Text == gongyi.Text)
24                 {
25                     gongyi = item as GongYi;
26                     gongyi.Activate();
27                     flag = true;
28                     break;
29                 }
30             }
31             if (!flag)
32             {
33                 gongyi.Show();
34                 //给子窗体指定父窗体
35                 gongyi.MdiParent = this;
36             }
37         }
38         #endregion      
View Code

二、关闭所有的运行环境操作

 1       /// <summary>
 2         /// 关闭运行环境
 3         /// </summary>
 4         /// <param name="sender"></param>
 5         /// <param name="e"></param>
 6         private void 关闭全部窗体ToolStripMenuItem_Click(object sender, EventArgs e)
 7         {
 8             //关闭运行环境
 9             Environment.Exit(0);
10         }    

三、右键菜单关闭所有弹窗(右键菜单有多个选项时的情况)

 1 private void CloseAllToolStripMenuItem_Click(object sender, EventArgs e)
 2         {
 3  
 4              int len = this.MdiChildren.Length;
 5              for (int i = 0; i <len ; i++)
 6              {
 7                  Form frm = this.MdiChildren[0];
 8                  frm.Close();
 9              }
10          }

 四、获取radiobatton的text值的方法

 1  private void btnNanNv_Click(object sender, EventArgs e)
 2         {
 3             string checkedRBName = "";
 4 
 5             //取得选中单选按钮的名称  
 6             if (radioButtonMan.Checked)
 7             {
 8                 checkedRBName = radioButtonMan.Name;
 9                 string textNan = radioButtonMan.Text;
10                 MessageBox.Show("这是选中了"+textNan);
11             }
12             else if (radioButtonGirl.Checked)
13             {
14                 checkedRBName = radioButtonGirl.Name;
15                 string textNv = radioButtonGirl.Text;
16                 MessageBox.Show("这是选中了"+ textNv);
17                 //获得和radioButton按钮对应标签的内容,用的是 radioButton2.Text属性;  
18 
19             }
20             
21             MessageBox.Show(checkedRBName + " was checked."); 
22         }

 

posted @ 2017-08-29 20:16  青红造了个白  阅读(650)  评论(0编辑  收藏  举报