当前位置: 首页 > 工具软件 > Form Tooltip > 使用案例 >

C# Display a tooltip on disabled textbox (Form)

牛华皓
2023-12-01

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?

Many thanks

c#
textbox
controls
tooltip
Share
Edit
Follow
edited Jun 3 '12 at 8:27

THelper
14k66 gold badges5858 silver badges9595 bronze badges
asked Oct 25 '11 at 10:21

tripbrock
91244 gold badges1313 silver badges2828 bronze badges
Add a comment
3 Answers

17

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;
    }
}

enter image description here

Share
Edit
Follow
answered Oct 25 '11 at 10:40

Stecya
21.4k88 gold badges6767 silver badges100100 bronze badges
One further thought - how would this be applied to a textbox within a groupbox? – tripbrock Oct 25 '11 at 12:39
2
then you should sign for groupBox MouseMove Event and do the same thing as for Form – Stecya Oct 25 '11 at 13:37
This is can be more reliable: textBox1.Name == this.GetChildAtPoint(e.Location).Name – Abhinav Jan 15 '19 at 18:28
Add a comment

0

Late to the party, but had the same problem and found a better solution: you can just wrap your TextBox in another Item and put a ToolTip on it like:

Share Edit Follow answered Jul 23 '20 at 9:45

Simas Paškauskas
9977 bronze badges
Add a comment

0

You can also drag a ToolTip object from the Toolbox in designer onto the form. Then in the code you just call SetToolTip() and pass in the button or text box etc. you want the tool tip to assign to and the text you want it to show.

myToolTip.SetToolTip(myTextBox, “You just hovered over myTextBox!”);
Share
Edit
Follow
answered Feb 28 '13 at 22:11

Josh P
1,1271313 silver badges1212 bronze badges
2
Except when the control is disabled you won’t see a tool tip. That’s the point of his question. – Script and Compile Mar 9 '16 at 1:29
Add a comment

 类似资料: