picturebox图片拖动

 
Private   Sub Form_Load()
    
    Image1.Picture 
= LoadPicture(Me.ImgPath)

    FitForm Image1
    Image1.Stretch 
= True
End Sub



Private   Sub Form_Resize()
    
Call CenterImage(Image1)
End Sub


Private   Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
gX 
= X
gY 
= Y
End Sub



Private   Sub Image1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Not Button = vbLeftButton Then Exit Sub
Dim dx As Long, dy As Long, ax As Long, ay As Long, t As Long, l As Long, tt As Long, ll As Long
With Image1
    dy 
= Y - gY
    dx 
= X - gX
    ll 
= .Left
    tt 
= .Top
    l 
= Abs(ll)
    t 
= Abs(tt)
    ax 
= (.Width - l - Frame1.Width)
    ay 
= (.Height - t - Frame1.Height)
    
If ll > 0 Then
        dx 
= 0
    
Else
        
If dx < 0 Then
            
If Abs(dx) > ax Then dx = -ax
        
Else
            
If dx > l Then dx = l
        
End If
    
End If
    
If tt > 0 Then
        dy 
= 0
    
Else
        
If dy < 0 Then
            
If Abs(dy) > ay Then dy = -ay
        
Else
            
If dy > t Then dy = t
        
End If
    
End If
    .Move ll 
+ dx, tt + dy
End With
End Sub



Private   Sub CenterImage(dest As Image)
    dest.Move 
00
End Sub



Private   Sub FitForm(dest As Image)
    dest.Width 
= dest.Width + Width - ScaleWidth
    dest.Height 
= dest.Height + Height - ScaleHeight
    dest.Move (Form1.Width 
- Width) / 2, (Form1.Height - Height) / 2
End Sub
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值