Hi Andersch,
When a control is disabled, tooltip will not display on the control. But we
could force the tooltip to show by calling the ToolTip.Show method.
We should call this method to show tooltip when the mouse is hovering over
the control. However, since the control is disabled, all events of this
control won't be fired. So it's no use for us to handle the MouseHover
event of the control. Instead, we could handle the MouseMove event of the
form. In the form's MouseMove event handler, we check if the control
captures the mouse. If yes, we call the ToolTip.Show method.
The following is a sample. It requires you to add a button called button1
and a tooltip called toolTip1 onto the form and set the 'ToolTip on
toolTip1' property of the button1 to a text, e.g 'this is the tooltip for
button1'.
bool IsShown = false;
void Form1_MouseMove(object sender, MouseEventArgs e)
{
Control ctrl = this.GetChildAtPoint(e.Location);
if (ctrl != null)
{
if (ctrl == this.button1 && !IsShown)
{
string tipstring =
this.toolTip1.GetToolTip(this.button1);
this.toolTip1.Show(tipstring, this.button1,
this.button1.Width /2, this.button1.Height / 2);
IsShown = true;
}
}
else
{
this.toolTip1.Hide(this.button1);
IsShown = false;
}
}
Because the MouseMove event is raised for several times when the mouse
stays on the button1, I use a flag 'IsShown' to prevent the tooltip from
showing once again.
Hope this helps.
If you have anything unclear, please feel free to let me know.
Sincerely,
Linda Liu
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.