[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);//设置此窗体为活动窗体 [DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true, CallingConvention = CallingConvention.Winapi, CharSet = CharSet.Unicode)] private extern static IntPtr FindWindow(string lpClassName, string lpWindowName); //定义变量,句柄类型 public IntPtr Handle1; Handle1 = new IntPtr(0); Handle1 = FindWindow(null, Name); if (Handle1 != IntPtr.Zero) { SetForegroundWindow(Handle1);//置顶 }