VB当中有关Drag此拖拽系统的一个问题,我很菜鸟的,求大侠帮帮忙啦
发布网友
发布时间:2024-10-20 16:08
我来回答
共2个回答
热心网友
时间:2024-11-21 10:58
程序试了,是没有大问题的。
image2的dragmode属性设置为0。
第二个过程,试试这样:
Private Sub Image2_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Image2.Top = Y + Image2.Top
Image2.Left = X + Image2.Left
Image2.Visible = True
End Sub
热心网友
时间:2024-11-21 11:02
算法不精确。改善了一下。
Dim ctX As Single, ctY As Single
Private Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
ctX = X: ctY = Y
End Sub
Private Sub Image1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
MouseKj Image1, Button, Shift, X, Y '在窗口范围内拖动 Image1
End Sub
Private Sub Form_Load()
Me.Caption = "运行时在窗口范围内拖动控件Image1"
Image1.Picture = Me.Icon
End Sub
Private Sub MouseKj(Kj As Object, Button As Integer, Shift As Integer, X As Single, Y As Single)
'在窗口范围内拖动控件Image1 Kj
Dim x1 As Single, y1 As Single
If Button = 0 Then Kj.MousePointer = 5
If Button <> 1 Then Exit Sub
x1 = Kj.Left + X - ctX: y1 = Kj.Top + Y - ctY
If x1 < 0 Then x1 = 0
If x1 > Me.ScaleWidth - Kj.Width Then x1 = Me.ScaleWidth - Kj.Width
If y1 < 0 Then y1 = 0
If y1 > Me.ScaleHeight - Kj.Height Then y1 = Me.ScaleHeight - Kj.Height
Kj.Move x1, y1
End Sub