Fungsi Event Gotfocus yaitu terjadi pada saat focus object memasuki sebuah komponen . dan LostFocus kebalikan dari fungsi GotFocus yaitu terjadi pada saat focus object meninggalkan sebuah kompunen.
Private
Sub
txtUserID_LostFocus()
If
txtUserID.Text =
""
Then
MsgBox
"Harus diisi"
End
If
End
Sub
Private
Sub
txtUserID_GotFocus()
txtUserID.Text =
""
End
Sub
Contoh penerapan Fungsi Event LostFocus dan GotFocus seperti source code sederhana di bawah ini:
Option Explicit
Private m_FocusControl As Control
Private Sub HighlightControl(ByVal ctl As Control)
ctl.BackColor = RGB(&HC0, &HFF, &HFF)
End Sub
Private Sub UnHighlightControl(ByVal ctl As Control)
ctl.BackColor = vbWhite
End Sub
Private Sub txtCity_GotFocus()
HighlightControl txtCity
End Sub
Private Sub txtCity_LostFocus()
UnHighlightControl txtCity
End Sub
Private Sub txtFirstName_GotFocus()
HighlightControl txtFirstName
End Sub
Private Sub txtFirstName_LostFocus()
UnHighlightControl txtFirstName
End Sub
Private Sub txtLastName_GotFocus()
HighlightControl txtLastName
End Sub
Private Sub txtLastName_LostFocus()
UnHighlightControl txtLastName
End Sub
Private Sub txtState_GotFocus()
HighlightControl txtState
End Sub
Private Sub txtState_LostFocus()
UnHighlightControl txtState
End Sub
Private Sub txtStreet_GotFocus()
HighlightControl txtStreet
End Sub
Private Sub txtStreet_LostFocus()
UnHighlightControl txtStreet
End Sub
Private Sub txtZip_GotFocus()
HighlightControl txtZip
End Sub
Private Sub txtZip_LostFocus()
UnHighlightControl txtZip
End Sub
Private m_FocusControl As Control
Private Sub HighlightControl(ByVal ctl As Control)
ctl.BackColor = RGB(&HC0, &HFF, &HFF)
End Sub
Private Sub UnHighlightControl(ByVal ctl As Control)
ctl.BackColor = vbWhite
End Sub
Private Sub txtCity_GotFocus()
HighlightControl txtCity
End Sub
Private Sub txtCity_LostFocus()
UnHighlightControl txtCity
End Sub
Private Sub txtFirstName_GotFocus()
HighlightControl txtFirstName
End Sub
Private Sub txtFirstName_LostFocus()
UnHighlightControl txtFirstName
End Sub
Private Sub txtLastName_GotFocus()
HighlightControl txtLastName
End Sub
Private Sub txtLastName_LostFocus()
UnHighlightControl txtLastName
End Sub
Private Sub txtState_GotFocus()
HighlightControl txtState
End Sub
Private Sub txtState_LostFocus()
UnHighlightControl txtState
End Sub
Private Sub txtStreet_GotFocus()
HighlightControl txtStreet
End Sub
Private Sub txtStreet_LostFocus()
UnHighlightControl txtStreet
End Sub
Private Sub txtZip_GotFocus()
HighlightControl txtZip
End Sub
Private Sub txtZip_LostFocus()
UnHighlightControl txtZip
End Sub
Jika anda pingin mengembangkannya silakan klik Download
0 komentar:
Komentar Anda
Berikan komentar..