'---------------------------- frmMain.frm VERSION 5.00 Begin VB.Form Form1 Caption = "Form1" ClientHeight = 6060 ClientLeft = 60 ClientTop = 315 ClientWidth = 7350 LinkTopic = "Form1" ScaleHeight = 6060 ScaleWidth = 7350 StartUpPosition = 3 'Windows Default Begin VB.CommandButton cmd Caption = "Press Me :)" Height = 495 Index = 0 Left = 4380 TabIndex = 0 Top = 480 Width = 1695 End End Attribute VB_Name = "Form1" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Option Explicit Dim stemp As String Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) cmd(0).Left = 4380 cmd(0).Top = 2000 End Sub Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) pet_cmdcheck X, Y End Sub Private Sub cmd_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single) pet_cmdcheck X, Y End Sub Private Sub pet_cmdcheck(X, Y) Dim xcmd As Single Dim ycmd As Single Dim wcmd As Single Dim hcmd As Single Static dx As Single Static dy As Single If dx = 0 Or dy = 0 Then dx = X dy = Y End If wcmd = 0.6 * cmd(0).Width hcmd = 0.6 * cmd(0).Height xcmd = cmd(0).Left + (cmd(0).Width) / 2 ycmd = cmd(0).Top + (cmd(0).Height) / 2 If (Abs(X - xcmd) < wcmd) And (Abs(Y - ycmd) < hcmd) Then pet_cmdmove X, Y, dx, dy, cmd(0) cmd(0).Enabled = False Else 'do nothing cmd(0).Enabled = True End If dx = X dy = Y End Sub Private Sub pet_cmdmove(X, Y, dx As Single, dy As Single, obj As Object) 'i'd like to move it... move it...:-\ Dim derx As Single, dery As Single Dim newx As Single, newy As Single derx = X - dx dery = Y - dy newx = obj.Left + Sgn(derx) * obj.Width / 2 newy = obj.Top + Sgn(dery) * obj.Height / 2 If (newx + obj.Width) > Me.Width Then newx = 1 End If If newx < 0 Then newx = Me.Width - 2 * obj.Width End If If newy + obj.Height > Me.Height Then newy = 1 End If If newy < 1 Then newy = Me.Height - 2 * obj.Height End If cmd(0).Move newx, newy End Sub