建议用Form.showDialog()实现模态窗口

解决方案 »

  1.   

            private void button4_Click(object sender, EventArgs e)
            {
                Form2 form2 = new Form2( ); 
                form2.ShowDialog();  //此模式打开,只能对于当前窗体进行操作,而form2.Show()是以非模式打开,即可同时操作多个窗体
                form2.Dispose();
            }
      

  2.   

    if (ActiveMdiChild is Form1)               
                {
                    return;    
                } 
                else  
                {
                 if (this.ActiveMdiChild != null)  
                    {
                        this.ActiveMdiChild.Close(); 
                    }
                 Form1 F= new Form1();   
                   F.MdiParent = this;             
                 F.Show();
                }int Children_Count=this.MdiChildren.Length;
    for(int i=0;i<Children_Count;i++)
    {
    if(this.MdiChildren[i].WindowState==FormWindowState.Maximized )
    this.MdiChildren[i].WindowState=FormWindowState.Normal;
    }
      

  3.   

    建议用Form.showDialog()实现模态窗口
      

  4.   

    program.cs里:
    namespace justatry
    {
        public class abc  
        {
            public static int i = 0;  //全局变量,判断有没有窗体2
        }    static class Program
        {
            /// <summary>
            /// 应用程序的主入口点。
            /// </summary>
            [STAThread]        static void Main()
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Form1());
            }
        }
    }窗体一:
    namespace justatry
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
            private void button1_Click(object sender, EventArgs e)
            {
                if (abc.i == 0) //没有窗体2.则打开
                {
                    Form2 form2 = new Form2(); 
                    abc.i = 1; //打开后至1
                    form2.Show(); 
                }
                
            }
        }
    }窗体二:
    namespace justatry
    {
        public partial class Form2 : Form
        {
            public Form2()
            {
                InitializeComponent();
            }        private void Form2_Load(object sender, EventArgs e)
            {        }        protected override void OnFormClosing(  FormClosingEventArgs e)  //对关闭事件做重载
            {
                abc.i = 0; //回0
     
                base.OnFormClosing(e);  
            }  
        }
    }好了!
      

  5.   

    支持使用Form.showDialog();
    顶上!