如何打开最大化的Internet Explorer?

我必须使用C#打开最大化的Internet Explorer。 我尝试过以下方法:

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) { } 

我可以打开不同的大小,但我找不到如何打开最大化的IE。 我检查了msdn ,没有属性可以最大化。

请给我一些建议。

PS:我正在开发C#控制台应用程序,.Net4.5和VS2012

我会使用流程方法。

  1. 你可以启动任何可执行文件
  2. 它有一个属性,可以使您的流程最大化

     ProcessStartInfo startInfo = new ProcessStartInfo("IExplore.exe"); startInfo.WindowStyle = ProcessWindowStyle.Maximized; startInfo.Arguments = "www.google.com"; Process.Start(startInfo); 
 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; } } } 

快速google的“csharp最大化SHDocVw窗口”给出了这个例子:

 [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. } 

试试这个:

  var proc = new Process { StartInfo = { UseShellExecute = true, FileName = "http://localhost/client.html", WindowStyle = ProcessWindowStyle.Maximized } }; proc.Start();