Я пытаюсь отобразить всплывающую подсказку, когда мышь нависает над отключенным элементом управления. Поскольку отключенный элемент управления не обрабатывает никаких событий, я должен сделать это в родительской форме. Я решил сделать это, обработав событие MouseMove
в родительской форме. Здесь код, который выполняет задание:
void Form1_MouseMove(object sender, MouseEventArgs e)
{
m_toolTips.SetToolTip(this, "testing tooltip on " + DateTime.Now.ToString());
string tipText = this.m_toolTips.GetToolTip(this);
if ((tipText != null) && (tipText.Length > 0))
{
Point clientLoc = this.PointToClient(Cursor.Position);
Control child = this.GetChildAtPoint(clientLoc);
if (child != null && child.Enabled == false)
{
m_toolTips.ToolTipTitle = "MouseHover On Disabled Control";
m_toolTips.Show(tipText, this, 10000);
}
else
{
m_toolTips.ToolTipTitle = "MouseHover Triggerd";
m_toolTips.Show(tipText, this, 3000);
}
}
}
Код обрабатывает отображение всплывающей подсказки для отключенного элемента управления. Проблема в том, что когда мышь наводится над отключенным элементом управления, всплывающая подсказка снова закрывается и снова отображается. Из времени отображения, которое я добавил в подсказке, когда мышь находится выше родительской формы, событие MouseMove
вызывается примерно каждые 3 секунды, поэтому всплывающая подсказка обновляется каждые 3 секунды. Но когда мышь находится над отключенным элементом управления, всплывающая подсказка обновляется каждые 1 секунду. Кроме того, когда всплывающая подсказка обновляется выше формы, только текст обновляется с помощью краткой вспышки. Но когда всплывающая подсказка обновляется над отключенным элементом управления, окна всплывающей подсказки закрываются, как будто мышь переходит в активированный элемент управления, и всплывающая подсказка должна быть закрыта. но затем подсказка снова появляется.
Может кто-нибудь сказать мне, почему это? Спасибо.