Find position of mouse relative to control, rather than screen

后端 未结 3 1410
醉话见心
醉话见心 2021-01-27 06:32

I have a Picture Box called BGImage. I hope that when the user clicks on this I can capture the position of the mouse relative to BGImage.

I\'v

3条回答
  •  醉梦人生
    2021-01-27 07:29

    Add a mouse click event to your picture box
    Then use the MouseEventArgs to get the mouse position inside the picture box.
    This will give you the X and the Y location inside the picture box.

    Dim PPoint As Point
    Private Sub PictureBox1_MouseClick(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseClick
        PPoint = New Point(e.X, e.Y)
        MsgBox(Convert.ToString(PPoint))
    End Sub
    

提交回复
热议问题