Hi,

It is possible to open a webbrowser window with the below code.

I wonder how it would be possible to have the web browser docked at TOP of the desktop and
have the window stretched to LEFT and RIGHT of the desktop and also how to choose a HEIGHT
of the opened web browser window?

System.Diagnostics.Process.Start("opera.exe", "http://google.com");

ProcessStartInfo class has WindowStyle property:

System.Diagnostics.ProcessStartInfo startInfo;

startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.FileName = "opera.exe";
startInfo.Arguments = "http://google.com";
// Set WindowStyle property for the new process
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Maximized;

System.Diagnostics.Process.Start(startInfo);

HTH

Thanks,

It seems that either of maximized/minimized works as below code.

ProcessWindowStyle.Maximized
ProcessWindowStyle.Minimized

The other thing is that I don't want the window to be maximized.

I would need to have the windows docked at the TOP and both SIDES and then specify a height of the window, let us say 200 px.

How could this be done?

Edited 1 Year Ago by Darth Vader

I do not know any way to do it with pure .NET code. You have to use an API call instead. I used an example from http://www.pinvoke.net/default.aspx/user32.MoveWindow

I also added System.Diagnostics namespace to simplify code a bit. System.Runtime.InteropServices namespace is required to make API calls.

    using System.Diagnostics;
    using System.Runtime.InteropServices;


    // See http://www.pinvoke.net/default.aspx/user32.MoveWindow
    [DllImport("user32.dll", SetLastError = true)]
    internal static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);

    internal struct RECT
    {
        public int left;
        public int top;
        public int right;
        public int bottom;
    }

    private void button1_Click(object sender, EventArgs e)
    {

        System.Diagnostics.ProcessStartInfo startInfo; // Data for the process
        Process startedProc; // Created process object
        IntPtr hProc; // Handle to main window of the process
        RECT sizeRect; // Size information for the window

        startInfo = new System.Diagnostics.ProcessStartInfo();
        startInfo.FileName = "opera.exe";
        startInfo.Arguments = "http://google.com";

        // Get the new process object
        startedProc = Process.Start(startInfo);
        // Get the handle of it's window
        hProc = startedProc.MainWindowHandle;
        // Set the size of the window. Size and position information is stored in RECT structure
        sizeRect = new RECT();
        // Upper left corner
        sizeRect.top = 0;
        sizeRect.left = 0;
        // Width comes from the screen size
        sizeRect.right = Screen.PrimaryScreen.Bounds.Width;
        // Height is hardcoded in here. Value should be checked to be less or equal to Screen.PrimaryScreen.Bounds.Height
        sizeRect.bottom = 200; // 200 pixels

        // Resize the process window with the data collected above
        MoveWindow(hProc, sizeRect.top, sizeRect.left, sizeRect.right, sizeRect.bottom, true);
    }

Code has no error checking etc. which should be added.

HTH

This article has been dead for over six months. Start a new discussion instead.