WinForm ToolTip使用方法小结

http://www.jb51.net/article/53324.htm

这篇文章主要介绍了WinForm ToolTip使用方法小结,对C#初学者有一定的借鉴参考价值,需要的朋友可以参考下

本文针对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);
    }
  }
}


代码运行效果如下:



评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值