窗口父子俩

 1       ///   <summary>
 2           ///  判断子窗口是否已经打开
 3           ///   </summary>
 4           ///   <param name="aform"></param>
 5           ///   <returns></returns>
 6           static   bool  OpenOnce(System.Windows.Forms.Form  aform)
 7          {
 8               bool  result = false ;
 9               foreach (Form form  in  frmMain.MdiChildren )
10              {
11                   if (aform.Text == form.Text)
12                  {
13                      
14                      form.Activate();
15                      result = true ;
16                      
17                       break ;
18                  }
19                  
20              }
21               return  result;
22          }
23           ///   <summary>
24           ///  关闭指定的窗口
25           ///   </summary>
26           ///   <param name="aform"></param>
27           public   static   void   CloseChild(System.Windows.Forms.Form  aform)
28          {
29          
30               foreach (Form form  in  frmMain.MdiChildren )
31              {
32                   if (aform.Text == form.Text)
33                  {
34                      
35                      form.Close();
36                      
37                       break ;
38                  }
39 
40              }
41              
42          }
43           ///   <summary>
44           ///  以子窗体的形式显示窗体
45           ///   </summary>
46           ///   <param name="childForm"></param>
47           public   static    void  ShowChildWin(System.Windows.Forms.Form childForm)
48          {
49               if ( ! OpenOnce(childForm))
50              {
51                  childForm.MdiParent = frmMain;
52                  childForm.WindowState = FormWindowState.Maximized;
53                  childForm.Show();
54              }
55               else
56                  childForm.Dispose();
57          }
58 
59           ///   <summary>
60           ///  关闭所有子窗口
61           ///   </summary>
62           private   void  CloseAllChild()
63          {
64               foreach (Form form  in   this .MdiChildren )
65              {
66                  
67                  form.Close();                    
68                      
69              }            
70 
71          }

你可能感兴趣的:(父子)