c# - 如何在winform中的禁用按钮上显示工具提示?
问题描述
我有一个带有与之关联的工具提示的按钮,在启用按钮时可以正常工作。但我的要求是在禁用按钮时显示工具提示。我尝试了多种互联网上可用的解决方案,但没有解决方案有效。有任何想法吗?
我试过下面的代码:
public partial class Form1 : Form
{
private ToolTip _toolTip = new ToolTip();
private Control _currentToolTipControl = null;
public Form1()
{
InitializeComponent();
_toolTip.SetToolTip(this.button1, "My button1");
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
Control control = GetChildAtPoint(e.Location);
if (control != null)
{
if (!control.Enabled && _currentToolTipControl == null)
{
string toolTipString = _toolTip.GetToolTip(control);
// trigger the tooltip with no delay and some basic positioning just to give you an idea
_toolTip.Show(toolTipString, control, control.Width / 2, control.Height / 2);
_currentToolTipControl = control;
}
}
else
{
if (_currentToolTipControl != null) _toolTip.Hide(_currentToolTipControl);
_currentToolTipControl = null;
}
}
}
}
解决方案
推荐阅读
- airflow - Apache Airflow 树视图的 UI 错误?
- javascript - 如何使用TestCafe运行一些具有并发性的测试套件并在没有并发的情况下休息?
- google-photos-api - 仅使用共享链接访问 Google 相册
- java - 查找仅使用特定类型参数的一个特定属性的所有 Java 方法
- android - 如何在 Android Studio 3.4 上设置布局边距?
- python - 使用 matplotlib 为多行设置动画时不会删除旧行
- android - 在 AOSP 中使用 Dagger2
- tomcat - Nginx + Tomcat 在同一台服务器上工作
- session - requests-html HTTPSConnectionPoolRead 超时
- c# - 在wpf中对listview中的项目进行分组时如何在扩展器标题中绑定类属性