微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在IE中打开一个网页使用c#

如何在IE中打开网页,同时点击c#应用程序中的按钮。
我的目的是创建一个需要在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();

               }    
    }
}

原文地址:https://www.jb51.cc/html/233060.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐