代码已经做到了,防止重复打开,但是我再重复点击的时候,该窗体不能作为焦点还是最小化在下面    private void add_sell_Click(object sender, EventArgs e)
        {            if (add_chuku.sign == false)
            {
                add_chuku asss = new add_chuku();
                asss.MdiParent = this;
                add_chuku.sign = true;
                asss.ShowDialog();
                
            }
            else
            {
               return;
            }
        }

解决方案 »

  1.   

    正好我这篇适合你看
    http://blog.csdn.net/wuyazhe/archive/2010/06/24/5690850.aspx
      

  2.   

    在“Program.cs”里加入如下代码:
            [DllImport("user32.dll ")]
            public static extern void SetForegroundWindow(IntPtr hwnd);
            [DllImport("user32.dll ")]
            public static extern IntPtr GetForegroundWindow();        [DllImport("user32.dll ")]
            public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
            public static void ActiveiseLoginWindow(string name)
            {
                Process[] proc = Process.GetProcessesByName(name);            foreach (Process p in proc)
                {
                    SetForegroundWindow(p.MainWindowHandle);
                    ShowWindow(p.MainWindowHandle, 3);
                }        }      [STAThread]
            static void Main()
            {
                bool canCreateNew;
                Mutex mutex = new Mutex(true, "工程名", out canCreateNew);
                if (!canCreateNew)
                {
                    //throw new Exception("Can create two or more server!");
                    ActiveiseLoginWindow("工程名");                return;
                }            Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Form1());
                mutex.ReleaseMutex();
            }
      

  3.   

      
      private CustomerManagement.CustomerManger customanger;
            private void 客户信息ToolStripMenuItem_Click(object sender, EventArgs e)
            {
                if (customanger == null || customanger.IsDisposed)
                {
                    customanger = new AchievementManger.CustomerManagement.CustomerManger();
                    customanger.MdiParent = this;
                    customanger.Show();
                }
                else { customanger.Activate(); }
            }
      

  4.   

    add_chuku.sign == false  //这个是变量用来判断什么呀,判断窗体是否打开???看哪个代码好像没有判断窗体是否有打开的呀..页首声明add_chuku asss 变量  if (add_chuku.sign == false)
      {
      asss = new add_chuku();
      asss.MdiParent = this;
      add_chuku.sign = true;
      asss.ShowDialog();
        
      }
      else
      {
      asss.Focus();
      return;
      }
      

  5.   

    add_chuku.sign == false
    这个就是判断窗体是否打开的。