本站之前也提供了一个类似的程序,但是那个程序限制当图片比窗体小时,必须将图片置于窗体左上角,否则程序执行会有问题。以下提供的程序去除了这个限制,同时当图片比窗体小时会将图片置于窗体中央,这样看起来比较美观。 Option Explicit Private gX As Long, gY As Long Private Sub Form_Load() Image1 = LoadPicture("c:winntwinnt256.bmp") '这个路径可能要改 FitForm Image1 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) |