[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);//置頂 }