|
|
|
|
|
Dicas
|
|
Visual Basic (Forms/MDI)
|
|
|
Título da Dica: Move os objetos de um form em tempo de execução
|
|
|
|
Postada em 31/7/2003 por Tekki
'Abra um formulário, adicione um CommandButton, 'um Label e um PictureBox 'Move tembém o Formulário sem barra de título 'Declare Dim MoveObjeto As Object Dim MoveForm As Form Dim MouseX As Long , MouseY As Long '----------------------- Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If (Button = 1) Then Set MoveObjeto = Command1 MouseX = X MouseY = Y End If End Sub
Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) If (Button = 1) Then Command1.Left = Command1.Left + X - MouseX Command1.Top = Command1.Top + Y - MouseY End If End Sub
Private Sub Form_Load() Me.BorderStyle = 0 Set MoveForm = Me End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = 1 Then MouseX = X MouseY = Y End If End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) If (Button = 1) And (MoveForm.WindowState <> 2) Then Screen.ActiveForm.Left = Screen.ActiveForm.Left + X - MouseX Screen.ActiveForm.Top = Screen.ActiveForm.Top + Y - MouseY End If End Sub
Private Sub Label1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = 1 Then Set MoveObjeto = Label1 MouseX = X MouseY = Y End If End Sub
Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) If (Button = 1) Then Label1.Left = Label1.Left + X - MouseX Label1.Top = Label1.Top + Y - MouseY End If End Sub
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If (Button = 1) Then Set MoveObjeto = Picture1 MouseX = X MouseY = Y End If End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) If (Button = 1) Then Picture1.Left = Picture1.Left + X - MouseX Picture1.Top = Picture1.Top + Y - MouseY End If End Sub
|
|
|
|
|