-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFormHelp.cs
More file actions
94 lines (83 loc) · 2.93 KB
/
Copy pathFormHelp.cs
File metadata and controls
94 lines (83 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AlarmTo
{
public partial class FormHelp : Form
{
public FormHelp()
{
InitializeComponent();
}
private void CloseBTN_Click(object sender, EventArgs e)
{
this.Hide();
}
private void FormHelp_Load(object sender, EventArgs e)
{
HelpTxt.DeselectAll();
}
private void BTN_tips_Click(object sender, EventArgs e)
{
LicenseTxt.Visible = false;
HelpTxt.Visible = true;
}
private void BTN_Lic_Click(object sender, EventArgs e)
{
LicenseTxt.Visible = true;
HelpTxt.Visible = false;
}
private void GoGitBTN_Click(object sender, EventArgs e)
{
string targetUrl = "https://github.com/overdoignism/AlarmTo";
BrowserLauncher.OpenUrl(targetUrl);
}
}
public class BrowserLauncher
{
public static void OpenUrl(string url)
{
try
{
// **推薦使用:** 這是跨平台且最安全的開啟網址方法
// 對於 .NET Core / .NET 5+,使用 ProcessStartInfo.UseShellExecute = true 是標準做法。
// 對於 .NET Framework,它通常是預設值。
Process.Start(new ProcessStartInfo(url) { UseShellExecute = true });
}
catch (Exception ex)
{
// 處理在特定系統上可能發生的異常,例如找不到關聯的應用程式。
// 由於 Process.Start 在不同作業系統上的行為差異,
// 這裡提供一個針對舊版/特殊環境的備用方案 (尤其是 Linux/macOS)。
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
// Windows 專用 (例如在 .NET Framework 環境下)
Process.Start(new ProcessStartInfo("cmd", $"/c start {url.Replace("&", "^&")}") { CreateNoWindow = true });
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
// Linux 專用
Process.Start("xdg-open", url);
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
// macOS 專用
Process.Start("open", url);
}
else
{
// 如果所有方法都失敗,可以輸出錯誤訊息
Console.WriteLine($"無法開啟網址 {url}. 錯誤: {ex.Message}");
}
}
}
}
}