這個問題在這里已經有了答案: 如何從 WPF 打開網頁?[重復] (2 個回答) 57 分鐘前關閉。
我看到每個人都推薦以下內容:
private void RegisterBtn(object sender, RoutedEventArgs e)
{
System.Diagnostics.Process.Start("https://website.com/");
}
但我收到以下錯誤:
“該系統找不到指定的檔案。” System.ComponentModel.Win32Exception"
我想讓按鈕在默認瀏覽器中打開一個視窗。
Ps:這是一個用 C# 撰寫的 WPF 桌面應用程式
uj5u.com熱心網友回復:
所以,我找到了這個答案:How to open a web page from WPF?
這正是我所問的,我知道如何將該答案與這個答案聯系起來。但這是代碼:
private void RegisterBtn(object sender, RoutedEventArgs e)
{
string url = "https://www.website.com";
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo("cmd", $"/c start {url}") { CreateNoWindow = true });
}
uj5u.com熱心網友回復:
嘗試explorer.exe顯式使用:
System.Diagnostics.Process.Start("explorer.exe", url);
或者您可以在 try catch 塊中使用它:
try
{
System.Diagnostics.Process.Start(url);
}
catch (Win32Exception ex)
{
System.Diagnostics.Process.Start("IExplore.exe", url);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/388360.html
下一篇:WPF多個UI同時更新
