【问题标题】:Launch winform with webrowser url from separate application从单独的应用程序使用 Web 浏览器 url 启动 winform
【发布时间】:2016-05-31 04:09:27
【问题描述】:

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

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

【问题讨论】:

  • Winforms 浏览器应用程序是什么意思?
  • 好吧...猜猜我描述它的方式是我创建了一个 .exe 文件,它基本上只是一个带有浏览器窗口的 .net winform。使用单独的 .exe 文件,我想控制 url。
  • 您可以从 url 运行普通的 windows 应用程序。但它与您在表单中托管的WebBrower 控件无关。 WebBrowser 控件的工作是显示Html 内容,它可能是离线或在线html 内容。
  • 基本上我想做的是我有一个 .exe .net 程序,我在其中制作了一个按钮。我希望该按钮中的单击事件启动我的第二个 .exe 文件,并更改第二个应用程序中的 WebBrowser URL
  • 这是一个更好的描述,您应该编辑问题并将其添加到问题中。并说出你想为WebBrowserControl 设置什么网址。

标签: c# .net winforms webbrowser-control


【解决方案1】:

因此,您需要在 2 个程序之间共享一些数据,这是一种方法:

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;
}

【讨论】:

  • 非常感谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-09-11
  • 2011-02-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多