VB.net 2010 视频教程 VB.net 2010 视频教程 VB.net 2010 视频教程
当前位置:
> 编程开发 > c#教程 >
  • C#教程之WinForm ToolTip使用方法小结

  • 2018-06-06 16:00 来源:未知

本文针对WinForm ToolTip使用方法进行实例总结,希望对大家学习C#程序设计有所帮助。具体如下:

程序功能代码如下:

?
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
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;
    }
  }
}

使用方法示例:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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);
    }
  }
}

代码运行效果如下:

相关教程
关于我们--广告服务--免责声明--本站帮助-友情链接--版权声明--联系我们       黑ICP备07002182号