C#WinForms:如何知道/检测工具提示是否正在显示/显示
我已经创建了一个工具提示。当鼠标位于图标上方时,通过调用工具提示的show方法显示此工具提示。我想知道当前是否显示此工具提示。如何做到这一点?也许是通过思考C#WinForms:如何知道/检测工具提示是否正在显示/显示,c#,winforms,reflection,tooltip,C#,Winforms,Reflection,Tooltip,我已经创建了一个工具提示。当鼠标位于图标上方时,通过调用工具提示的show方法显示此工具提示。我想知道当前是否显示此工具提示。如何做到这一点?也许是通过思考 System.Reflection.FieldInfo fi = typeof(ToolTip).GetField("window", BindingFlags.NonPublic | BindingFlags.Instance); fi.GetValue(someObject...) ... 然后请求是否可见?工具提示类在开始显示工具提
System.Reflection.FieldInfo fi = typeof(ToolTip).GetField("window", BindingFlags.NonPublic | BindingFlags.Instance);
fi.GetValue(someObject...) ...
然后请求是否可见?工具提示类在开始显示工具提示之前引发其弹出事件。您可以认为这是显示TT期间的时间跨度的开始。这段时间的结束是两件事中的第一件;显示工具提示的控件上的MouseLeave事件,指示用户不再将鼠标指向您显示工具提示的对象,或指示工具提示的AutoOpDelay时间段结束后,引出序号将淡出 因此,您可以使用表单中的代码或其他包含工具提示的控件来处理此问题,如下所示:
private System.Windows.Forms.Timer ToolTipTimer = new Timer();
public MyControl()
{
myToolTip.Popup += ToolTipPopup;
ToolTipTimer.Tick += ToolTipTimerTick;
ToolTipTimer.Enabled = false;
}
private bool IsToolTipShowing { get; set; }
private Control ToolTipControl { get; set; }
private void ToolTipPopup(object sender, PopupEventArgs e)
{
var control = e.AssociatedControl;
//optionally check to see if we're interested in watching this control's ToolTip
ToolTipControl = control;
ToolTipControl.MouseLeave += ToolTipMouseLeave;
ToolTipAutoPopTimer.Interval = myToolTip.AutoPopDelay;
ToolTipTimer.Start();
IsToolTipShowing = true;
}
//now one of these two should happen to stop the ToolTip showing on the currently-watched control
public void ToolTipTimerTick(object sender, EventArgs e)
{
StopToolTip();
}
public void ToolTipMouseLeave(object sender, EventArgs e)
{
StopTimer();
}
private void StopTimer()
{
IsToolTipShowing = false;
ToolTipTimer.Stop();
ToolTipControl.MouseLeave -= ToolTipMouseLeave;
}
可能重复的