gpt4 book ai didi

C# WinForms : How to know/detect if tooltip is being displayed/shown

转载 作者:行者123 更新时间:2023-11-30 16:21:16 25 4
gpt4 key购买 nike

我创建了一个工具提示。通过调用工具提示的 show 方法,当鼠标悬停在图标上时显示此工具提示。我想知道当前是否正在显示此工具提示。这个怎么做?也许通过反射(reflection)?

System.Reflection.FieldInfo fi = typeof(ToolTip).GetField("window", BindingFlags.NonPublic | BindingFlags.Instance);
fi.GetValue(someObject...) ...

然后请求是否可见?

最佳答案

ToolTip 类在开始显示工具提示之前引发其 Popup 事件。您可以将此视为显示 TT 的时间跨度的开始。该跨度的结束是两件事中的第一件事;显示工具提示的控件上的 MouseLeave 事件,指示用户不再将鼠标指向您显示工具提示的任何内容,或者工具提示的 AutoPopDelay 时间段结束后气球将淡出.

因此,您可以使用表单或其他包含工具提示的控件中的代码来处理此问题,如下所示:

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;
}

关于C# WinForms : How to know/detect if tooltip is being displayed/shown,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13387982/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com