Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Displaying tooltip over a disabled control

I'm trying to display a tooltip when mouse hovers over a disabled control. Since a disabled control does not handle any events, I have to do that in the parent form. I chose to do this by handling the MouseMove event in the parent form. Here's the code that does the job:

    void Form1_MouseMove(object sender, MouseEventArgs e)     {         m_toolTips.SetToolTip(this, "testing tooltip on " + DateTime.Now.ToString());         string tipText = this.m_toolTips.GetToolTip(this);         if ((tipText != null) && (tipText.Length > 0))         {             Point clientLoc = this.PointToClient(Cursor.Position);             Control child = this.GetChildAtPoint(clientLoc);             if (child != null && child.Enabled == false)             {                 m_toolTips.ToolTipTitle = "MouseHover On Disabled Control";                 m_toolTips.Show(tipText, this, 10000);             }             else             {                 m_toolTips.ToolTipTitle = "MouseHover Triggerd";                 m_toolTips.Show(tipText, this, 3000);             }         }     } 

The code does handles the tooltip display for the disabled control. The problem is that when mouse hovers over a disabled control, the tooltip keeps closing and redisplay again. From the display time I added in the tooltip, when mouse is above the parent form, the MouseMove event gets called roughly every 3 seconds, so the tooltip gets updated every 3 seconds. But when mouse is over a disabled control, the tooltip refreshes every 1 second. Also, when tooltip refreshes above form, only the text gets updated with a brief flash. But when tooltip refreshes above a disabled control, the tooltip windows closes as if mouse is moving into a enabled control and the tooltip is supposed to be closed. but then the tooltip reappears right away.

Can someone tell me why is this? Thanks.

like image 446
DJ. Avatar asked Nov 13 '09 21:11

DJ.


1 Answers

you can show the tooltip only once when mouse hits the disbled control and then hide it when mouse leaves it. Pls, take a look at the code below, it should be showing a tooltip message for all the disabled controls on the form

private ToolTip     _toolTip = new ToolTip(); private Control     _currentToolTipControl = null;   public Form1() {     InitializeComponent();      _toolTip.SetToolTip(this.button1, "My button1");     _toolTip.SetToolTip(this.button2, "My button2");     _toolTip.SetToolTip(this.textBox1, "My text box"); }  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;     } } 

hope this helps, regards

like image 90
serge_gubenko Avatar answered Oct 08 '22 15:10

serge_gubenko