Laravel  
laravel
文档
数据库
架构
入门
php技术
    
Laravelphp
laravel / php / java / vue / mysql / linux / python / javascript / html / css / c++ / c#

c# tooltip

作者:半盏流年   发布日期:2026-03-22   浏览:97

using System;
using System.Windows.Forms;

namespace TooltipExample
{
    public class TooltipForm : Form
    {
        private ToolTip toolTip1;
        private Button button1;

        public TooltipForm()
        {
            // 初始化按钮
            button1 = new Button();
            button1.Text = "Hover over me!";
            button1.Location = new System.Drawing.Point(50, 50);
            this.Controls.Add(button1);

            // 初始化 ToolTip
            toolTip1 = new ToolTip();
            toolTip1.SetToolTip(button1, "This is a tooltip message.");

            // 设置 ToolTip 的显示时间
            toolTip1.AutoPopDelay = 5000; // 显示5秒后自动消失
            toolTip1.InitialDelay = 1000; // 鼠标悬停1秒后显示
            toolTip1.ReshowDelay = 500;   // 再次显示的延迟时间
        }

        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new TooltipForm());
        }
    }
}

解释说明:

  1. 创建窗体和按钮:我们创建了一个 TooltipForm 类,继承自 Form。在构造函数中,初始化了一个按钮 button1 并将其添加到窗体上。
  2. ToolTip 控件:使用 ToolTip 类创建了一个工具提示控件 toolTip1,并调用 SetToolTip 方法为按钮设置了提示文本。
  3. 设置显示时间:通过设置 AutoPopDelayInitialDelayReshowDelay 属性来控制工具提示的显示时间和行为。
  4. 运行应用程序:在 Main 方法中启动应用程序并显示窗体。

这个示例展示了如何在 C# WinForms 应用程序中使用 ToolTip 控件为按钮添加提示信息。

上一篇:c# serializable

下一篇:c#获取list集合中某一元素的值

大家都在看

c# 二进制

c# 创建目录

c# datatable group by

c# tcp client

c# type.gettype

c# sqlconnection

c# string.format 小数位数

.net和c#

c#获取系统时间

c#游戏开发

Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3

Laravel 中文站