In my application, I want to open an url in the browser but want to fix the size of the window.
In Javascript, we can do that easily like below.
I am trying to achieve it in C# windows application.
popUp = window.open('http://www.google.com','Test','scrollbars,width=600,height=430');
Could not find any option using
System.Diagnostics.Process.Start(url);
Basically, I want to open a window with a fixed size.
Should be something to achieve that.
Chromium browser has this ability to process commandline arguments, for example:
Open window in predefined size:
--window-size Sets the initial window size. Provided as string in the format "800,600".
Start chromium with URL or multiple URLs(multiple tabs)
chromium-browser firefox.com [ubuntu.com duckduckgo.com]
Link to chrommium commandline switches.
So something like this:
Process runProg = new Process();
//With path to your chromium browser
runProg.StartInfo.FileName = "path/to/chromium.exe";
//Command line arguments for launch
runProg.StartInfo.Arguments = "--window-size" +" "+ "800,600" + "AnyThingYouWish";
runProg.StartInfo.CreateNoWindow = true;
//And start your application
runProg.Start();
I would probably consider using a WebBrowser control anchored on a form that you then set the size of on load. Would be a lot easier than trying to launch it in a browser and you would retain more control over what happens, for example you would know when the form is closed and may wish to handle that event whereas you would struggle/have to put in more work to managing that with a browser.
Given that you are sure to be dealing with only Chrome, your best bet is to launch the executable directly, using command line parameters.
chrome.exe --window-size=800,600 "https://www.google.com"
However, in the likely event that the browser is already open, this won't resize the exsting browser window. Which is exactly as it should be.
https://peter.sh/experiments/chromium-command-line-switches/#window-size
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.