C# C“过程.开始”;chrome.exe";/申报高度
嗨,我正在尝试使用C# C“过程.开始”;chrome.exe";/申报高度,c#,google-chrome,C#,Google Chrome,嗨,我正在尝试使用 process start 'chrome.exe' 它正在发挥作用: private void btnSTBAutoLogin_Click(object sender, EventArgs e) { try { System.Diagnostics.Process.Start("CHROME.EXE", "https://www.google.com/chrome/browser/desktop/index.html
process start 'chrome.exe'
它正在发挥作用:
private void btnSTBAutoLogin_Click(object sender, EventArgs e)
{
try
{
System.Diagnostics.Process.Start("CHROME.EXE", "https://www.google.com/chrome/browser/desktop/index.html");
}
catch
{
System.Diagnostics.Process.Start("IEXPLORE.EXE", "https://www.google.com/chrome/browser/desktop/index.html");
}
}
问题:
我想在单击btnSTBAutoLogin
时调整chrome页面的大小
我可以调整chrome页面的大小吗?
例:
- 身高:1280
- 宽度:800
using System.Diagnostics;
using System.Runtime.InteropServices;
下一步-添加p/Invoke代码:
[DllImport("user32.dll", SetLastError = true)]
internal static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool GetWindowRect(IntPtr hWnd, ref Rect lpRect);
[StructLayout(LayoutKind.Sequential)]
private struct Rect
{
public int Left;
public int Top;
public int Right;
public int Bottom;
}
最后,在您的过程之后。开始您可以使用此过程,更改chrome窗口大小:
public void SetChromeSize(int width, int height)
{
var procsChrome = Process.GetProcessesByName("chrome"); // there are always many chrome processes, so we have to find the process with a WindowHandle
foreach (var chrome in procsChrome)
{
if (chrome.MainWindowHandle == IntPtr.Zero) // the chrome process must have a window
continue;
var rct = new Rect();
GetWindowRect(chrome.MainWindowHandle, ref rct); // find and use current position of chrome window
MoveWindow(chrome.MainWindowHandle, rct.Left, rct.Top, width, height, true); //use MoveWindow to change size and save current position
break;
}
}
你可以参考这个我调整这个代码。但是当我第一次单击按钮时,SetChromeSize不起作用。所以我使用延迟时间。谢谢你的回复!