[WinForm]ToolTip 使用小计

2020-12-13 04:39

阅读:260

标签:winform   style   blog   http   color   使用   

关键代码:

using System.Drawing;
using System.Windows.Forms;

namespace WinFormUtilHelpV2
{
    /// 
    /// 基于.NET 2.0的Tooltip工具类
    /// 
    public static class TooltipToolV2
    {
        /// 
        /// 为控件提供Tooltip
        /// 
        /// 控件
        /// ToolTip
        /// 提示消息
        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;
        }
        /// 
        /// 为控件提供Tooltip
        /// 
        /// 控件
        /// ToolTip
        /// 提示消息
        /// 保持提示的持续时间
        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;
        }
        /// 
        /// 为控件提供Tooltip
        /// 
        /// 控件
        /// ToolTip
        /// 提示消息
        /// 水平偏移量
        /// 垂直偏移量
        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;
        }
        /// 
        /// 为控件提供Tooltip
        /// 
        /// 控件
        /// ToolTip
        /// 提示消息
        /// 水平偏移量
        /// 垂直偏移量
        /// 保持提示的持续时间
        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);
        }
    }
}

代码效果:

soscw.com,搜素材

soscw.com,搜素材

[WinForm]ToolTip 使用小计,搜素材,soscw.com

[WinForm]ToolTip 使用小计

标签:winform   style   blog   http   color   使用   

原文地址:http://www.cnblogs.com/Yan-Zhiwei/p/3842602.html


评论


亲,登录后才可以留言!