Force Windows Forms (Winforms) toolstrip tooltip to refresh or hide immediately using C#
If you are using the tooltip text on a ToolStrip control you may find that the control does not update the tooltip immediately and the tooltip may not hide when you start a long running process leaving the tooltip stuck on the screen.
The toolstrip actually has a tooltip control under the hood which you can access with reflection.
Calling RemoveAll on the tooltip control will immediately remove all tooltips.
https://learn.microsoft.com/dotnet/api/system.windows.forms.tooltip.removeall
/// <summary>
/// Occurs when the user clicks the toolstrip button.
/// </summary>
/// <param name="sender">The control that raised the event.</param>
/// <param name="e">The event arguments.</param>
private void ToolStripButton_Click(object sender, EventArgs e)
{
ToolTip toolTip = (ToolTip)toolStrip.GetType().GetProperty("ToolTip", System.Reflection.BindingFlags.NonPublic |
System.Reflection.BindingFlags.Instance).GetValue(toolStrip);
toolTip.RemoveAll();
}
We needed this when displaying a Microsoft Authentication MSAL interactive login prompt which left the stray "Sign in to a Microsoft account" tooltip whilst the dialog was shown.
Comments
Post a Comment