【问题标题】:Window management in C#C#中的窗口管理
【发布时间】:2021-10-16 07:28:07
【问题描述】:

我正在使用 selenium c# 进行 Web 自动化,但我在安排窗口时遇到了问题。请参阅所附图片,了解我正在努力实现的目标。

【问题讨论】:

  • 请提供足够的代码,以便其他人更好地理解或重现问题。

标签: selenium selenium-webdriver window


【解决方案1】:

过了一会儿,我找到了解决方法。

  1. 每次打开一个窗口时,我都会得到它的句柄
[DllImport("user32.dll", SetLastError = true)]
 private static extern IntPtr GetForegroundWindow();

并存储它。

  1. 我通过以下方式获取屏幕尺寸:
int h = (int)Screen.PrimaryScreen.Bounds.Height;
int w = (int)Screen.PrimaryScreen.Bounds.Width;
  1. 我使用该功能根据需要划分屏幕并排列窗口:
 [DllImport("user32.dll", SetLastError = true)]
internal static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);

Results

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-01-20
    • 1970-01-01
    • 1970-01-01
    • 2022-08-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多