gpt4 book ai didi

vb.net - 如何通过用鼠标单击并按住对象来移动元素?

转载 作者:行者123 更新时间:2023-12-03 20:38:02 25 4
gpt4 key购买 nike

我正在开发一个简单的程序,它要求我能够选择一个图片框并通过用鼠标拖动将其移动到新位置。这是我目前提出的所有相关代码。但是,当我运行该程序时,它会尝试移动到我想要它去的地方,然后它似乎又回到了以前的位置。

编辑:它在一个容器中。如果这有任何意义。

变量

Dim startx As Integer
Dim starty As Integer
Dim endy As Integer
Dim endx As Integer
Dim finalx As Integer
Dim finaly As Integer
Dim mdown As Boolean
Dim valx As Boolean
Dim valy As Boolean

使图像移动的代码
Private Sub picbox_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) 处理 picbox.MouseDown
startx = 鼠标位置.X
starty = MousePosition.Y
mdown = 真
valx = 错误
瓦利 = 错误
结束子
Private Sub Main_MouseMove(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove

End Sub

Private Sub picbox_MouseMove(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles picbox.MouseMove
'Check if mouse=down
If mdown = True Then
endx = (MousePosition.X - Me.Left)
endy = (MousePosition.Y - Me.Top)

If valy = False Then
starty = endy - sender.top
valy = True
End If
If valx = False Then
startx = endx - sender.left
valx = True
End If
sender.left = endx - startx
sender.top = endy - starty


End If
End Sub

Private Sub picbox_MouseUp(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles picbox.MouseUp
mdown = False
valx = False
valy = False

End Sub

最佳答案

关闭 Autosize属性(property)。

关于vb.net - 如何通过用鼠标单击并按住对象来移动元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11196016/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com