EVENTS PROGRAMMING

Form Events

Visual Basic forms and controls can trigger dozens of events in your applications. Forms, controls, and classes all have events. Let's look at some of the events for forms, and examine how and when they occur.

Visual Basic form events

Event Program

Private Sub Command1_Click()
Print "Click Event"
End Sub

Private Sub Command1_DragDrop(Source As Control, X As Single, Y As Single)
Print "Click Event"
End Sub

Private Sub Command1_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
Print "Click DragOver"
End Sub

Private Sub Command1_GotFocus()
Print "Click GotFocus"
End Sub

Private Sub Command1_KeyDown(KeyCode As Integer, Shift As Integer)
Print "Click KeyDown"
End Sub

Private Sub Command1_KeyPress(KeyAscii As Integer)
Print "Click KeyPress"
End Sub

Private Sub Command1_KeyUp(KeyCode As Integer, Shift As Integer)
Print "Click KeyUp"
End Sub

Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Print "Click MouseDown"
End Sub

Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Print "Click MouseMove"
End Sub

Private Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Print "Click MouseUp"
End Sub