Private Sub Form_Load() Picture1.AutoSize = -1 ' 打开 AutoSize。 Picture1.AutoRedraw = True End Sub Private Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) Image1.Drag ' 拖标签轮廓。 End SubPrivate Sub Picture1_DragDrop(Source As Control, X As Single, Y As Single) Set Image1.Container = Picture1 Image1.Move X, Y Image1.ZOrder End Sub
Option ExplicitPrivate m_StartX As Single Private m_StartY As SinglePrivate Sub Image1_DragDrop(Source As Control, X As Single, Y As Single) If Source Is Image1 Then If Not Image1.Container Is Picture1 Then Exit Sub Image1.Move Image1.Left + (X - m_StartX), Image1.Top + (Y - m_StartY) End If End SubPrivate Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = vbLeftButton Then m_StartX = X m_StartY = Y Image1.DragIcon = Image1.Picture Image1.Drag vbBeginDrag End If End SubPrivate Sub Picture1_DragDrop(Source As Control, X As Single, Y As Single) If Source Is Image1 Then Set Image1.Container = Picture1 Image1.Move X - m_StartX, Y - m_StartY End If End Sub
方案1:改成将Image1的图片直接画到Picture1上,然后用你的方法查找坐标 Private Sub Picture1_DragDrop(Source As Control, X As Single, Y As Single) If Source Is Image1 Then Picture1.PaintPicture Image1.Picture, X - m_StartX, Y - m_StartY End If End Sub方案2:预先将 Image1 图片透明/蓝色的点标记在一个2纬Boolean数组中,DragDrop 时将蓝色点的坐标加上放下位置的坐标偏移就是覆盖坐标。
试一下吧:一定用picture1当image1的容器。Option Explicit Dim X As Long Dim Y As Long Private m_StartX As Single Private m_StartY As SinglePrivate Sub Image1_DragDrop(Source As Control, X As Single, Y As Single) If Source Is Image1 Then If Not Image1.Container Is Picture1 Then Exit Sub Image1.Move Image1.Left + (X - m_StartX), Image1.Top + (Y - m_StartY) End If End SubPrivate Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = vbLeftButton Then m_StartX = X m_StartY = Y Image1.Drag vbBeginDrag End If End Sub Private Sub Picture1_DragDrop(Source As Control, X As Single, Y As Single) If Source Is Image1 Then Set Image1.Container = Picture1 Image1.Move X - m_StartX, Y - m_StartY End If End Sub Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) Image1.Visible = True Image1.Top = Y End SubPrivate Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = 2 Then '鼠标右键 Image1.Top = Picture1.Height Picture1.PaintPicture Image1.Picture, X, Y, Image1.Width, Image1.Height, 0, 0 End If End Sub
Picture1.AutoSize = -1 ' 打开 AutoSize。
Picture1.AutoRedraw = True
End Sub
Private Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Image1.Drag ' 拖标签轮廓。
End SubPrivate Sub Picture1_DragDrop(Source As Control, X As Single, Y As Single)
Set Image1.Container = Picture1
Image1.Move X, Y
Image1.ZOrder
End Sub
Private m_StartY As SinglePrivate Sub Image1_DragDrop(Source As Control, X As Single, Y As Single)
If Source Is Image1 Then
If Not Image1.Container Is Picture1 Then Exit Sub
Image1.Move Image1.Left + (X - m_StartX), Image1.Top + (Y - m_StartY)
End If
End SubPrivate Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then
m_StartX = X
m_StartY = Y
Image1.DragIcon = Image1.Picture
Image1.Drag vbBeginDrag
End If
End SubPrivate Sub Picture1_DragDrop(Source As Control, X As Single, Y As Single)
If Source Is Image1 Then
Set Image1.Container = Picture1
Image1.Move X - m_StartX, Y - m_StartY
End If
End Sub
Private Sub Picture1_DragDrop(Source As Control, X As Single, Y As Single)
If Source Is Image1 Then
Picture1.PaintPicture Image1.Picture, X - m_StartX, Y - m_StartY
End If
End Sub方案2:预先将 Image1 图片透明/蓝色的点标记在一个2纬Boolean数组中,DragDrop 时将蓝色点的坐标加上放下位置的坐标偏移就是覆盖坐标。
GDI中也只有一个alphablend函数支持alpha通道。
Dim X As Long
Dim Y As Long
Private m_StartX As Single
Private m_StartY As SinglePrivate Sub Image1_DragDrop(Source As Control, X As Single, Y As Single)
If Source Is Image1 Then
If Not Image1.Container Is Picture1 Then Exit Sub
Image1.Move Image1.Left + (X - m_StartX), Image1.Top + (Y - m_StartY)
End If
End SubPrivate Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then
m_StartX = X
m_StartY = Y
Image1.Drag vbBeginDrag
End If
End Sub
Private Sub Picture1_DragDrop(Source As Control, X As Single, Y As Single)
If Source Is Image1 Then
Set Image1.Container = Picture1
Image1.Move X - m_StartX, Y - m_StartY
End If
End Sub
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Image1.Visible = True
Image1.Top = Y
End SubPrivate Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 2 Then '鼠标右键
Image1.Top = Picture1.Height
Picture1.PaintPicture Image1.Picture, X, Y, Image1.Width, Image1.Height, 0, 0
End If
End Sub