[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);//置顶 }
C# WinForm 获取句柄与置顶窗体
猜你喜欢
转载自www.cnblogs.com/shigure/p/12799932.html
今日推荐
周排行