使用来自单独应用程序的webrowser url启动winform

时间:2016-05-31 04:09:28

标签: c# .net winforms webbrowser-control

基本上我想要做的是我有一个.exe .net程序,我用它做了一个按钮。我希望该按钮中的click事件启动我的第二个.exe文件,并更改该第二个应用程序中的WebBrowser URL。这可能吗?

网址将是我计算机上的html页面。

1 个答案:

答案 0 :(得分:1)

所以你需要在两个程序之间分享一些数据,这是一种方法:

private void btnLaunchBrowser_Click(object sender, EventArgs e)
{
    string yourExePath = "WhateverIsThePath.exe";
    string url = "YourLocalUrlHere";
    var browserWinformsApp = System.Diagnostics.Process.Start(yourExePath, url);
    // Here you can control over the second Process, you can even 
    // Force it to Close by browserWinformsApp.Close();
}

在您的第二个应用程序(浏览器一个)中,更新Program.cs以接受parameters

static class Program
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main(string[] args)
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);

        string passedUrl = args[0];
        Application.Run(new Form1(passedUrl));
    }
}

最后,更新您的Form's构造函数以接受string url

private string browserUrl;
public Form1(string url)
{
    InitializeComponent();
    browserUrl= url;
}