C# 在禁用的文本框(表单)上显示工具提示 [英] C# Display a tooltip on disabled textbox (Form)

查看:24
本文介绍了C# 在禁用的文本框(表单)上显示工具提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在鼠标悬停期间在禁用的文本框上显示工具提示.我知道因为控件被禁用,所以以下内容不起作用:

I am trying to get a tooltip to display on a disabled textbox during a mouse over. I know because the control is disabled the following won't work:

private void textBox5_MouseHover(object sender, EventArgs e)
{
       // My tooltip display code here
}

如何在鼠标悬停在禁用控件上时显示工具提示?

How can I get the tooltip to display on a mouse over of a disabled control?

非常感谢

推荐答案

如果禁用控制,MouseHover 不会触发.相反,您可以检查 Form MouseMove 事件是否悬停文本框

MouseHover wont fire if control is disabled. Instead you can check in Form MouseMove event whether you hover the textbox

    public Form1()
    {
        InitializeComponent();
        textBox1.Enabled = false;
        toolTip.InitialDelay = 0;
    }

    private ToolTip toolTip = new ToolTip();
    private bool isShown = false;

    private void Form1_MouseMove(object sender, MouseEventArgs e)
    {
        if(textBox1 == this.GetChildAtPoint(e.Location))
        {
            if(!isShown)
            {
                toolTip.Show("MyToolTip", this, e.Location);
                isShown = true;
            }
        }
        else
        {
            toolTip.Hide(textBox1);
            isShown = false;
        }
    }

这篇关于C# 在禁用的文本框(表单)上显示工具提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆