WinForm ToolTip應用辦法小結。本站提示廣大學習愛好者:(WinForm ToolTip應用辦法小結)文章只能為提供參考,不一定能成為您想要的結果。以下是WinForm ToolTip應用辦法小結正文
本文針對WinForm ToolTip應用辦法停止實例總結,願望對年夜家進修C#法式設計有所贊助。詳細以下:
法式功效代碼以下:
using System.Drawing; using System.Windows.Forms; namespace WinFormUtilHelpV2 { /// <summary> /// 基於.NET 2.0的Tooltip對象類 /// </summary> public static class TooltipToolV2 { /// <summary> /// 為控件供給Tooltip /// </summary> /// <param name="control">控件</param> /// <param name="tip">ToolTip</param> /// <param name="message">提醒新聞</param> public static void ShowTooltip(this Control control, ToolTip tip, string message) { Point _mousePoint = Control.MousePosition; int _x = control.PointToClient(_mousePoint).X; int _y = control.PointToClient(_mousePoint).Y; tip.Show(message, control, _x, _y); tip.Active = true; } /// <summary> /// 為控件供給Tooltip /// </summary> /// <param name="control">控件</param> /// <param name="tip">ToolTip</param> /// <param name="message">提醒新聞</param> /// <param name="durationTime">堅持提醒的連續時光</param> public static void ShowTooltip(this Control control, ToolTip tip, string message, int durationTime) { Point _mousePoint = Control.MousePosition; int _x = control.PointToClient(_mousePoint).X; int _y = control.PointToClient(_mousePoint).Y; tip.Show(message, control, _x, _y, durationTime); tip.Active = true; } /// <summary> /// 為控件供給Tooltip /// </summary> /// <param name="control">控件</param> /// <param name="tip">ToolTip</param> /// <param name="message">提醒新聞</param> /// <param name="xoffset">程度偏移量</param> /// <param name="yoffset">垂直偏移量</param> public static void ShowTooltip(this Control control, ToolTip tip, string message, int xoffset, int yoffset) { Point _mousePoint = Control.MousePosition; int _x = control.PointToClient(_mousePoint).X; int _y = control.PointToClient(_mousePoint).Y; tip.Show(message, control, _x + xoffset, _y + yoffset); tip.Active = true; } /// <summary> /// 為控件供給Tooltip /// </summary> /// <param name="control">控件</param> /// <param name="tip">ToolTip</param> /// <param name="message">提醒新聞</param> /// <param name="xoffset">程度偏移量</param> /// <param name="yoffset">垂直偏移量</param> /// <param name="durationTime">堅持提醒的連續時光</param> public static void ShowTooltip(this Control control, ToolTip tip, string message, int xoffset, int yoffset, int durationTime) { Point _mousePoint = Control.MousePosition; int _x = control.PointToClient(_mousePoint).X; int _y = control.PointToClient(_mousePoint).Y; tip.Show(message, control, _x + xoffset, _y + yoffset, durationTime); tip.Active = true; } } }
應用辦法示例:
using System; using System.Windows.Forms; using WinFormUtilHelpV2; namespace TooltipToolV2Test { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { button1.ShowTooltip(toolTip, "button1_Click"); } private void listBox1_Click(object sender, EventArgs e) { listBox1.ShowTooltip(toolTip, "listBox1_Click", 500); } } }
代碼運轉後果以下: