簡體   English   中英

如何打開最大化的Internet Explorer?

[英]How do I open maximized 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

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;
        }
    }
}

我會使用流程方法。

  1. 你可以啟動任何可執行文件
  2. 它有一個屬性,可以使您的流程最大化

     ProcessStartInfo startInfo = new ProcessStartInfo("IExplore.exe"); startInfo.WindowStyle = ProcessWindowStyle.Maximized; startInfo.Arguments = "www.google.com"; Process.Start(startInfo); 

快速谷歌的“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();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM