Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 控件的错误位置_.net_Vb.net_Winforms_Picturebox - Fatal编程技术网

.net 控件的错误位置

.net 控件的错误位置,.net,vb.net,winforms,picturebox,.net,Vb.net,Winforms,Picturebox,这是我的密码: Dim Offset As Point Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles PictureBox1.MouseDown Offset = New Point(-e.X, -e.Y) End Sub Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVa

这是我的密码:

Dim Offset As Point

Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles PictureBox1.MouseDown
    Offset = New Point(-e.X, -e.Y)
End Sub

Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) Handles PictureBox1.MouseMove
    If e.Button = Windows.Forms.MouseButtons.Left Then
        Dim Pos As Point = Me.PointToClient(MousePosition)
        Pos.Offset(Offset.X, Offset.Y)
        PictureBox1.Location = Pos
    End If
End Sub
我可以做用户想要做的事情,(拖动图片并添加按钮),尽管..
问题1
每当我在面板内拖动pictureBox时,无论我带到哪里,它都会稍微向右偏移一点。从技术上讲,当我移动鼠标时,picturebox只是在按照鼠标顺序移动之前向右移动,我知道这只是一个小错误,但我不能让用户看到它


希望你们能帮忙!谢谢大家!

您需要存储picturebox的原始客户端位置(鼠标按下),并在此点进行偏移:

Private offset As Point
Private pbpos As Point

Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles PictureBox1.MouseDown
    Me.pbpos = Me.PictureBox1.Location
    Me.offset = Control.MousePosition
End Sub

Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) Handles PictureBox1.MouseMove
    If (e.Button = Windows.Forms.MouseButtons.Left) Then
        Me.PictureBox1.Location = New Point((Me.pbpos.X + (Control.MousePosition.X - Me.offset.X)), (Me.pbpos.Y + (Control.MousePosition.Y - Me.offset.Y)))
    End If
End Sub

如果你需要顾问,那就雇佣一些。这个网站是为了帮助你纠正错误的代码,而不是为你编写全新的代码。问题1似乎与主题有关。请删除问题2和3。另外,请将问题限制为单个问题。您可以针对遇到的每个问题发布单独的问题。