Windorm和WPF等应用程序想自己获取焦点焦点那是不可能的,只能通过系统的API来实现
[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);//设置此窗体句柄的窗体为活动窗体 
上面第一个函数获取的是当前窗体的句柄, 如果窗体应用要获取自己的句柄的话就使用下面的方法获取
private IntPtr ptr;
ptr = this.Handle; 
拿到句柄的话我们就可以使用SetForegroundWindow将窗体设置为前台应用
这可以能还不够,等它失去焦点的时候我们让它重新获取焦点
// 添加焦点丢失监听
LostFocus += OnLostFocus;
private void OnLostFocus(object sender, EventArgs e)
{
	new Thread(new ThreadStart(delegate {
		Thread.Sleep(1000);
		if(TopMost)
			SetForegroundWindow(ptr);
	})).Start();
}









