C# BUTTON按钮能设置让鼠标停在上面出悬浮字吗

来源:百度知道 编辑:UC知道 时间:2024/06/19 23:42:12
鼠标放上能出提示字 如何设置

你可以使用ToolTip 类 表示一个长方形的小弹出窗口,该窗口在用户将指针悬停在一个控件上时显示有关该控件用途的简短说明。

private void Form1_Load(object sender, System.EventArgs e)
{
// 创建the ToolTip
ToolTip toolTip1 = new ToolTip();

// 设置显示样式
toolTip1.AutoPopDelay = 5000;
toolTip1.InitialDelay = 1000;
toolTip1.ReshowDelay = 500;
// Force the ToolTip text to be displayed whether or not the form is active.
toolTip1.ShowAlways = true;

// 设置伴随的对象.
toolTip1.SetToolTip(this.button1, "My button1");
}

1. 为窗体添加一个ToolTip控件,命名为toolTip,并且设置Title属性为你想要出现提示字的标题(一般是应用程序的名字)
2. 在Button的MouseEnter事件中加入以下代码,实现使用ToolTip显示悬浮字: toolTip.Show("TEST", (Button)sender);

拖个 ToolTip 控件去看看吧!