Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I open maximized internet explorer?

I have to open maximized internet explorer using C#. I have tried the following:

try
{
    var IE = new SHDocVw.InternetExplorer();
    object URL = "http://localhost/client.html";

    IE.ToolBar = 0;
    IE.StatusBar = true;
    IE.MenuBar = true;
    IE.AddressBar = true;
    IE.Width = System.Windows.Forms.SystemInformation.VirtualScreen.Width;
    IE.Height = System.Windows.Forms.SystemInformation.VirtualScreen.Height;

    IE.Visible = true;

    IE.Navigate2(ref URL);
    ieOpened = true;

    break;
}
catch (Exception)
{

}

I can open with different sizes, but I couldn't find how to open maximized IE. I have checked the msdn, there is no property to for maximize.

Please give me some suggestions.

PS: I am developing C# console application, .Net4.5, and VS2012

like image 315
Balu Avatar asked Dec 05 '22 05:12

Balu


2 Answers

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace Maximize_IE
{
    class Program
    {
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        [return: MarshalAs(UnmanagedType.Bool)]
        private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

        static void Main(string[] args)
        {
            var IE = new SHDocVw.InternetExplorer();
            object URL = "http://google.com/";

            IE.ToolBar = 0;
            IE.StatusBar = true;
            IE.MenuBar = true;
            IE.AddressBar = true;

            IE.Visible = true;
            ShowWindow((IntPtr)IE.HWND, 3);
            IE.Navigate2(ref URL);
            //ieOpened = true;
        }
    }
}
like image 141
Arkadiusz Kałkus Avatar answered Dec 22 '22 01:12

Arkadiusz Kałkus


I would use the process method.

  1. You could start any executable and
  2. It has a property which starts your process maximized

    ProcessStartInfo startInfo = new ProcessStartInfo("IExplore.exe");
    startInfo.WindowStyle = ProcessWindowStyle.Maximized;
    startInfo.Arguments = "www.google.com";
    
    Process.Start(startInfo);
    
like image 43
N1C0 Avatar answered Dec 22 '22 01:12

N1C0