不管点桌面哪里,焦点一直在该窗体上

解决方案 »

  1.   

     System.Diagnostics.Process[] pcs = System.Diagnostics.Process.GetProcessesByName(Application.ProductName);
                if (pcs.GetLength(0) > 1)
                {                foreach (System.Diagnostics.Process pc in pcs)
                    {
                        GeneralControls.CLSAPI.ShowWindowAsync(pc.MainWindowHandle.ToInt32(), GeneralControls.CLSAPI.SW_SHOWMAXIMIZED);   //调用api函数,正常显示窗口 
                        GeneralControls.CLSAPI.SetForegroundWindow(pc.MainWindowHandle.ToInt32());   //将窗口放置最前端。
                    }
                    return;
                }
      

  2.   

    有一个ShowDialog,可是这个仅对本应用程序有用,其他非本程序的位置还是可以点击
      

  3.   

    他好像是说点其他应用程序.ShowDialog()应该起不了作用吧。
      

  4.   

    设置窗体TopMost属性为True.保证窗体 只在最前应该就可以
      

  5.   

    看看是这个吗.
    http://noi1600.blog.163.com/blog/static/274772372010111322345365/
      

  6.   

    通过设置定时器System.Timers.Timer timer = null;        private void SetWinFocus()
            {
                timer = new System.Timers.Timer();
                timer.Interval = 1000;
                timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
                timer.Enabled = true;
                timer.Start();
            }        void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
            {
                if (GetForegroundWindow() == this.Handle)
                {            }
                else
                {
                    SetForegroundWindow(this.Handle);
                }
            }        [System.Runtime.InteropServices.DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto, ExactSpelling = true)]
            public static extern IntPtr GetForegroundWindow();
            [System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "SetForegroundWindow")]
            public static extern bool SetForegroundWindow(IntPtr hwnd);
      

  7.   

    设置窗体TopMost属性为True. 只在最前应该就可以