PictureBox工具提示显示 [英] PictureBox Tooltip Display

查看:92
本文介绍了PictureBox工具提示显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,当我将鼠标悬停在图片框上时,我想显示一个工具提示。但问题是,我只想在当前鼠标位置显示它。



代码:

Hallo, I want to display a tooltip, when i hover on picturebox. But the problem is, that I want to show it only on current mouse position.

Code:

private void picturebox1_MouseHover(object sender, EventArgs e)
        {
            ToolTip tt = new ToolTip();

            if (e.X >= 18 && e.X <= 71 && e.Y >= 21 && e.Y <= 79)
            {
                tt.SetToolTip(this.picturebox1, "something");
            }

            else
            {
                tt.Hide(this.picturebox1);
            }
        }





但Mouse_Hover不响应鼠标位置ex和ey,Mouse_Move每次显示它,当光标移动时...感谢您的回答。



But Mouse_Hover do not respond on mouse position e.x and e.y and Mouse_Move show it everytime, when cursor moves... Thanks for answer.

推荐答案

是的,MouseHover事件不使用MouseEventHandler所以你没有得到ex和ey另一种方法是获取Cursors位置,因为你在表单中使用PointToClient来获得正确的位置。



Yes the MouseHover event does not use the MouseEventHandler so you don't get the e.x and e.y. Another way to do this is to get the Cursors position, and since your in a form use PointToClient to get the correct location.

private void picturebox1_MouseHover(object sender, EventArgs e)
{
    ToolTip tt = new ToolTip();
    Point p = pictureBox1.PointToClient(System.Windows.Forms.Cursor.Position);

    if (p.X >= 18 && p.X <= 71 && p.Y >= 21 && p.Y <= 79)
    {
        tt.SetToolTip(this.picturebox1, "something");
    }

    else
    {
        tt.Hide(this.picturebox1);
    }
}


这篇关于PictureBox工具提示显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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