如何在单击ac#应用程序中的按钮时在IE中打开网页.我的目的是为ac#应用程序创建一个web登录,需要在IE中以指定的宽度和高度打开,并且需要在应用程序中调用一个函数.
Tzu*_*hay 41
来自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();
}
}
}
Run Code Online (Sandbox Code Playgroud)
RaY*_*ell 18
System.Diagnostics.Process.Start("iexplore", "http://example.com");
Run Code Online (Sandbox Code Playgroud)
有一种方法可以在默认浏览器中打开页面 System.Diagnostics.Process.Start(url);
如果你想专门在IE中打开它,你可能需要创建一个以URL作为参数的新IE进程.
UPD:如果要运行函数,请将GET参数插入到url字符串(即.http://stackoverflow.com/page?runFunction=1)中,并在应用程序代码中检查runFunction参数,并根据其值确定应用程序是否需要运行该函数.
我不认为可以指定新的IE窗口宽度和高度值,您可能需要使用javascript.
| 归档时间: |
|
| 查看次数: |
76645 次 |
| 最近记录: |