110,566
社区成员
发帖
与我相关
我的任务
分享
[System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "GetForegroundWindow")]
public static extern IntPtr GetForegroundWindow();
[System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "GetWindowRect")]
public static extern int GetWindowRect(IntPtr hwnd, ref System.Drawing.Rectangle lpRect);
private static void TestGetForegroundWindowRectangle()
{
IntPtr hForeground = GetForegroundWindow();
System.Drawing.Rectangle rect = new System.Drawing.Rectangle();
GetWindowRect(hForeground, ref rect);
//这里的rect就是你你要的
}
Rectangle rect = new Rectangle(窗体对象.Left,窗体对象.Top,窗体对象.Width,窗体对象.Height);