从单独的应用程序使用 webrowser url 启动 winform
Launch winform with webrowser url from separate application
基本上我想做的是我制作了一个带有按钮的 .exe .net 程序。我希望该按钮中的单击事件启动我的第二个 .exe 文件,并更改第二个应用程序中的 WebBrowser URL。这可能吗?
这些网址将是我计算机上的 html 个页面。
因此您需要在 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;
}
基本上我想做的是我制作了一个带有按钮的 .exe .net 程序。我希望该按钮中的单击事件启动我的第二个 .exe 文件,并更改第二个应用程序中的 WebBrowser URL。这可能吗?
这些网址将是我计算机上的 html 个页面。
因此您需要在 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;
}