WinForm ToolTip使用方法小结
程序员文章站
2023-12-18 11:16:16
本文针对winform tooltip使用方法进行实例总结,希望对大家学习c#程序设计有所帮助。具体如下:
程序功能代码如下:
using system.dra...
本文针对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); } } }
代码运行效果如下: