如何在当前鼠标位置设置工具提示?

如何在当前鼠标位置设置工具提示?

问题描述:

我注册了热键: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.

我希望这会有所帮助.