using System; using System.Drawing; using System.Windows.Forms; public class MainForm : Form { private Label myLabel; private ToolTip toolTip; public MainForm() { // 初始化組件 InitializeComponent(); } private void InitializeComponent() { this.myLabel = new Label(); this.toolTip = new ToolTip(); // 設置 Label this.myLabel.Text = "Hover over me!"; this.myLabel.Location = new Point(50, 50); this.myLabel.AutoSize = true; this.myLabel.ForeColor = Color.Blue; // 設置為藍色以模擬超鏈接 this.myLabel.Cursor = Cursors.Hand; // 設置鼠標樣式為手形 // 設置 ToolTip this.toolTip.ToolTipTitle = "Information"; this.toolTip.ToolTipIcon = ToolTipIcon.Info; this.toolTip.SetToolTip(this.myLabel, "This is a tooltip with a hyperlink!"); // 添加事件處理程序 this.myLabel.MouseClick += MyLabel_MouseClick; // 添加 Label 到窗體 this.Controls.Add(this.myLabel); // 設定窗體的其他屬性 this.Text = "ToolTip Hyperlink Example"; this.Size = new Size(300, 200); } private void MyLabel_MouseClick(object sender, MouseEventArgs e) { // 當 Label 被點擊時,打開一個網址 System.Diagnostics.Process.Start("https://www.example.com"); } [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainForm()); } }