如何在当前鼠标位置设置工具提示? [英] How to set tooltip at current mouse location?

查看:29
本文介绍了如何在当前鼠标位置设置工具提示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注册了热键:Ctrl + Space.热键消息发送至:

I registered Hotkey: Ctrl + Space. Hotkey message is sent to:

private void Hotkey_press()
{
... // I want to show tooltip "Hello" at current mouse location.
}

有没有办法显示这个工具提示,即使鼠标没有指向任何控件并且它在我的 Window.Form1 之外?

Is there any way to show this tooltip even the mouse doesnt point to any control and it is outside my Window.Form1?

该工具提示甚至可以显示失去焦点或隐藏的表单

推荐答案

你想要的东西

ToolTip tt = new ToolTip();
IWin32Window win = this;
tt.Show("String", win, mousePosition);

其中 MousePosition 可以通过

private SomeMouseEventHandler(object sender, MouseEventArgs e)
{
    System.Drawing.Point mousePosition = e.Location;
    ...
}

或使用

System.Drawing.Point mousePosition = Cursor.Position;

此外,您可能希望设置更长的显示ToolTip 的持续时间,只需使用Show 方法可用的重载,tt.Show("String", win, mousePosition, 5000); 将显示工具提示 5 秒.

also, you may want to set a longer duration for which the ToolTip is displayed, well just use the overloads available for the Show method, tt.Show("String", win, mousePosition, 5000); will display the tool tip for 5 seconds.

我希望这会有所帮助.

这篇关于如何在当前鼠标位置设置工具提示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆