4

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

Ralt
  • 2,084
  • 1
  • 26
  • 38
Balu
  • 137
  • 2
  • 11
  • _Off topic:_ Why is there a `break` statement? – sampathsris Aug 13 '14 at 10:16
  • @Krumia on top of it there is while loop which checks for other dependenices to open the IE – Balu Aug 13 '14 at 10:18
  • Here's a hack: Maybe you can use [`TheaterMode`](http://msdn.microsoft.com/en-us/library/aa752077(v=vs.85).aspx), and then set properties like `MenuBar` afterwards to get the desired output. – sampathsris Aug 13 '14 at 10:20

4 Answers4

7
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;
        }
    }
}
Arkadiusz Kałkus
  • 17,101
  • 19
  • 69
  • 108
5

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);
    
sampathsris
  • 21,564
  • 12
  • 71
  • 98
N1C0
  • 121
  • 4
3

Quick google of "csharp maximize SHDocVw window" gives this example:

[DllImport ("user32.dll")]
private static extern bool ShowWindow(IntPtr hwnd, int nCmdShow);
private const int SW_MAXIMISE = 3;

public void OpenWindow()
{
       SHDocVw.InternetExplorer ie = new SHDocVw.InternetExplorer();  //Instantiate the class.
        ShowWindow((IntPtr)ie.HWND, SW_MAXIMISE);   //Maximise the window.
        ie.Visible = true;   //Set the window to visible.
}
user2771704
  • 5,994
  • 6
  • 37
  • 38
Ihor Deyneka
  • 1,326
  • 1
  • 19
  • 37
1

try this:

  var proc = new Process
            {
              StartInfo = {
                 UseShellExecute = true,
                 FileName = "http://localhost/client.html",
                 WindowStyle = ProcessWindowStyle.Maximized
              }
            };
  proc.Start();
Robert
  • 3,276
  • 1
  • 17
  • 26