Пример #1
0
 public void ActivateWindow(bool bActive)
 {
     if (this.InvokeRequired)
     {
         _ActivateWindow d = new _ActivateWindow(ActivateWindow);
         this.Invoke(d, new object[] { bActive });
     }
     else
     {
         if (bActive == true)
         {
             if (this.WindowState == FormWindowState.Minimized)
             {
                 this.WindowState = FormWindowState.Normal;
             }
             this.TopMost = true;
             // SetForegroundWindow(this.Handle);    // 接受键盘输入
         }
         else
         {
             this.TopMost     = false;
             this.WindowState = FormWindowState.Minimized;
         }
     }
 }
Пример #2
0
        public void ActivateWindow(bool bActive)
        {
            if (this.InvokeRequired)
            {
                _ActivateWindow d = new _ActivateWindow(ActivateWindow);
                this.Invoke(d, new object[] { bActive });
            }
            else
            {
                if (bActive == true)
                {
                    if (this.WindowState == FormWindowState.Minimized)
                    {
                        this.WindowState = FormWindowState.Normal;
                    }

                    // 如果 this.TopMost 不奏效,可以试试下面这个 URL 里面的方法
                    // https://stackoverflow.com/questions/5282588/how-can-i-bring-my-application-window-to-the-front

                    /*
                     * {
                     *  this.WindowState = FormWindowState.Minimized;
                     *  this.Show();
                     *  this.WindowState = FormWindowState.Normal;
                     * }
                     */


                    this.TopMost = true;
                    // SetForegroundWindow(this.Handle);    // 接受键盘输入
                }
                else
                {
                    this.TopMost     = false;
                    this.WindowState = FormWindowState.Minimized;
                }
            }
        }