c# - 使用c#在IE中打开网页

标签 c#

如何在 C# 应用程序中单击按钮时在 IE 中打开网页。 我的目的是为需要在 IE 中打开的 c# 应用程序创建一个 Web 登录,指定的宽度和高度,并且需要在应用程序中调用一个函数。

最佳答案

来自 http://msdn.microsoft.com/en-us/library/system.diagnostics.process(VS.71).aspx

using System;
using System.Diagnostics;
using System.ComponentModel;

namespace MyProcessSample
{
    /// <summary>
    /// Shell for the sample.
    /// </summary>
    public class MyProcess
    {

        /// <summary>
        /// Opens the Internet Explorer application.
        /// </summary>
        public void OpenApplication(string myFavoritesPath)
        {
            // Start Internet Explorer. Defaults to the home page.
            Process.Start("IExplore.exe");

            // Display the contents of the favorites folder in the browser.
            Process.Start(myFavoritesPath);

        }

        /// <summary>
        /// Opens urls and .html documents using Internet Explorer.
        /// </summary>
        public void OpenWithArguments()
        {
            // url's are not considered documents. They can only be opened
            // by passing them as arguments.
            Process.Start("IExplore.exe", "www.northwindtraders.com");

            // Start a Web page using a browser associated with .html and .asp files.
            Process.Start("IExplore.exe", "C:\\myPath\\myFile.htm");
            Process.Start("IExplore.exe", "C:\\myPath\\myFile.asp");
        }

        /// <summary>
        /// Uses the ProcessStartInfo class to start new processes, both in a minimized 
        /// mode.
        /// </summary>
        public void OpenWithStartInfo()
        {

            ProcessStartInfo startInfo = new ProcessStartInfo("IExplore.exe");
            startInfo.WindowStyle = ProcessWindowStyle.Minimized;

            Process.Start(startInfo);

            startInfo.Arguments = "www.northwindtraders.com";

            Process.Start(startInfo);

        }

        public static void Main()
        {
                    // Get the path that stores favorite links.
                    string myFavoritesPath = 
                    Environment.GetFolderPath(Environment.SpecialFolder.Favorites);

                    MyProcess myProcess = new MyProcess();

            myProcess.OpenApplication(myFavoritesPath);
            myProcess.OpenWithArguments();
            myProcess.OpenWithStartInfo();

               }    
    }
}

关于c# - 使用c#在IE中打开网页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1431115/

相关文章:

c# - 使用 TransactionScope 的嵌套事务

c# - 使用 k__backingfield 格式化 JsonMediaTypeFormatter

c# - 将文件夹目录中的所有文件无循环上传到谷歌云存储

c# - 有Point3D吗?

c# - 分割并添加空间

c# - Linq - 子对象上的where子句

c# - 如何避免在 Entity Framework 中加载集合属性

c# - Xamarin 中的日志记录库和 MetroLog 中的错误报告样式

c# - 使用rest api更新sharepoint中的多项选择字段

c# - 如何模拟 DirectoryInfo 类?