Displaying tooltip over a disabled control

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


The answer turned out to be a bit simpler, but needed to be applied at all times.

void OrderSummaryDetails_MouseMove(object sender, MouseEventArgs e)
{
      Control control = GetChildAtPoint(e.Location);
      if (control != null)
      {
          string toolTipString = mFormTips.GetToolTip(control);
          this.mFormTips.ShowAlways = true;
          // trigger the tooltip with no delay and some basic positioning just to give you an idea
          mFormTips.Show(toolTipString, control, control.Width / 2, control.Height / 2);
      }
}