Prova questo codice: ha il solo difetto che nn puoi uscire dallo schermo
codice:
Dim MouseDown_Flag As Boolean
Dim MouseDownPos_X As Integer
Dim MouseDownPos_Y As Integer
'Questa modificala quanto vuoi
'o la puoi mettere nel pannello opzioni del tuo programma
'se la fai variabile
Const Arrotonda As Integer = 180 'In twip
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
MouseDown_Flag = True
MouseDownPos_X = X
MouseDownPos_Y = Y
pt = Me.Top
pl = Me.Left
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If MouseDown_Flag Then
Dim iTop As Integer, iLeft As Integer
iTop = Me.Top + (Y - MouseDownPos_Y)
iLeft = Me.Left + (X - MouseDownPos_X)
If iTop - Arrotonda <= 0 Then
'In questo caso attacca il form in alto
iTop = 0
ElseIf iTop + Arrotonda + Me.Height >= Screen.Height Then
'In questo caso attacca il form in basso
iTop = Screen.Height - Me.Height
End If
If iLeft - Arrotonda <= 0 Then
'In questo caso attacca il form a sinistra
iLeft = 0
ElseIf iLeft + Arrotonda + Me.Width >= Screen.Width Then
'In questo caso attacca il form a destra
iLeft = Screen.Width - Me.Width
End If
Me.Top = iTop
Me.Left = iLeft
End If
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
MouseDown_Flag = False
End Sub