如何在C#应用程序中点击按钮时在IE中打开一个网页。 我的意图是为C#应用程序创建一个Web登录,需要在指定的宽度和高度中在IE中打开,并需要调用应用程序中的一个函数。
如何在C#应用程序中点击按钮时在IE中打开一个网页。 我的意图是为C#应用程序创建一个Web登录,需要在指定的宽度和高度中在IE中打开,并需要调用应用程序中的一个函数。
来自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();
}
}
}
System.Diagnostics.Process.Start("iexplore", "http://example.com");
有一种方法可以在默认浏览器中打开页面System.Diagnostics.Process.Start(url);
如果您想特别在IE中打开它,您可能需要使用URL作为参数创建一个新的IE进程。
更新:如果您想运行一个函数,请将GET参数插入到您的url字符串中(例如:http://stackoverflow.com/page?runFunction=1
),并且在您的应用程序代码中检查runFunction参数,并根据其值决定您的应用程序是否需要运行该函数。
我认为不可能指定新的IE窗口宽度和高度值,您可能需要使用javascript来实现。