VB2010 在窗体上获取鼠标位置 [英] VB2010 Get Mouse Position On Form

查看:44
本文介绍了VB2010 在窗体上获取鼠标位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一个未最大化的表单.我在 MouseDown 子中有一些代码,当我单击表单时,它会给我一个具有鼠标单击位置的 msgbox.问题是当我移动表单并在同一位置单击时,它不会给我相同的位置.它给了我窗口屏幕的位置,而不是表单.有什么办法可以解决这个问题吗?

i currently have a form that is not maximized. I have some code in the MouseDown sub that when i click on the form, it will give me a msgbox that has the mouse click position. The problem is that when i move the form and click at the same location, it does not give me the same location. It is giving me the position of the window screen, not the form. Is there a way i can fix this?

代码:

sub MouseDown.......

msgbox Mouseposition.x & ", " & mouseposition.y
end sub

推荐答案

如果你想要客户坐标使用eXeY:

If you want client coords use e.X and e.Y:

Private Sub Form1_MouseDown(sender As Object, e As MouseEventArgs) Handles MyBase.MouseDown
    MessageBox.Show(e.X & ", " & e.Y)
End Sub

这篇关于VB2010 在窗体上获取鼠标位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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