Menjadikan Isi Textbox Sebagai Label Field pada Form Inputan di VB6

Pada pertemuan kali ini saya akan membagikan sebuah trik yaitu sebuah isi textbox kita jadikan sebagai nama fileld dalam pembuatan form, hal ini bertujuan untuk menghemat tempat, apalagi form itu dirancang dengan banyak Tabel Form.

Contoh dibawah ini adalah sebuah Form yang saya maksud

Output Form
Pada umumnya kita membuat form dengan memberi Label pada sisi kiri textbox tapi pada kali ini saya akan membagi triknya agar nama label tersebut berada dalam textbox sebagai judul keterangan input.
Bagaiman apkah Anda tertarik untuk membuatnya, yuk ikutilah langkah-langkah berikut agar tidak tersesat :

1. Tambahkan sebuah Form baru dengan standar EXE
2. Tanamkan 4 Textbox pada Form
3. Desainlah seperti gambar dibawah ini :

Desain Form

Selanjutnya kita kan memasang kodenya.copylah kode dibawah ini :

Private Sub Form_Load()
Text1.Text = "Nama Lengkap"
Text1.Appearance = 0
Text1.ForeColor = &HC0C0C0
Text1.FontBold = True


Text2.Text = "No.Identitas"
Text2.Appearance = 0
Text2.ForeColor = &HC0C0C0
Text2.FontBold = True

Text3.Text = "Alamat"
Text3.Appearance = 0
Text3.ForeColor = &HC0C0C0
Text3.FontBold = True

Text4.Text = "No.Tlp"
Text4.Appearance = 0
Text4.ForeColor = &HC0C0C0
Text4.FontBold = True
End Sub

Private Sub Text1_Click()
If Text1.Text = "Nama Lengkap" Then
Text1.Text = ""
Text1.ForeColor = vbBlack
End If
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
Text1.ForeColor = vbBlack
If KeyAscii = 13 Then
Text2.SetFocus
Text2.Text = ""

End If

If Text1.Text = "Nama Lengkap" Then
Text1.Text = ""
Text1.ForeColor = vbBlack
End If
End Sub

Private Sub Text1_LostFocus()
If Text1.Text = "" Then
Text1.Text = "Nama Lengkap"
Text1.ForeColor = &HC0C0C0
End If
End Sub

Private Sub Text2_Click()
If Text2.Text = "No.Identitas" Then
Text2.Text = ""
Text2.ForeColor = vbBlack
End If
End Sub

Private Sub Text2_KeyPress(KeyAscii As Integer)
Text2.ForeColor = vbBlack
If Not (KeyAscii >= Asc("0") And KeyAscii <= Asc("9") Or KeyAscii = vbKeyBack Or KeyAscii = vbKeyDelete Or KeyAscii = vbKeySpace Or KeyAscii = vbKeyReturn) Then
MsgBox "Maaf Hanya Boleh Diisi Angka Saja", vbInformation + vbOKOnly, "Perhatian"
KeyAscii = 0
End If


If KeyAscii = 13 Then
Text3.SetFocus
Text3.Text = ""

End If
If Text2.Text = "No.Identitas" Then
Text2.Text = ""
Text2.ForeColor = vbBlack
End If
End Sub

Private Sub Text2_LostFocus()
If Text2.Text = "" Then
Text2.Text = "No.Identitas"
Text2.ForeColor = &HC0C0C0
End If
End Sub

Private Sub Text3_Click()
If Text3.Text = "Alamat" Then
Text3.Text = ""
Text3.ForeColor = vbBlack
End If
End Sub

Private Sub Text3_KeyPress(KeyAscii As Integer)
Text3.ForeColor = vbBlack
If KeyAscii = 13 Then
Text4.SetFocus
Text4.Text = ""
End If

If Text3.Text = "Alamat" Then
Text3.Text = ""
Text3.ForeColor = vbBlack
End If
End Sub

Private Sub Text3_LostFocus()
If Text3.Text = "" Then
Text3.Text = "Alamat"
Text3.ForeColor = &HC0C0C0
End If
End Sub

Private Sub Text4_Click()
If Text4.Text = "No.Tlp" Then
Text4.Text = ""
Text4.ForeColor = vbBlack
End If
End Sub

Private Sub Text4_KeyPress(KeyAscii As Integer)
Text4.ForeColor = vbBlack
If KeyAscii = 13 Then

If Text4.Text = "No.Tlp" Then
Text4.Text = ""
Text4.ForeColor = vbBlack
End If
Command1.SetFocus
End If

End Sub

Private Sub Text4_LostFocus()
If Text4.Text = "" Then
Text4.Text = "No.Tlp"
Text4.ForeColor = &HC0C0C0
End If
End Sub

3. Kemudian doubel klik area Form kosong, maka muncul jendela kode Form.
4. Pada jendela kode tekan CRTL+A kemudian DEL untuk membersihkan kode yang ada di jendela Form tesebut, lalu Pastekan kode yang tadi di copy dengan CTRL+V.
5. Sekarang jalankan program Anda, cobalah untuk mengisi form sebagai mana mestinya sesuai label yang ada didalamnya.

Demikianlah trik dari saya tentang Menjadikan Isi Textbox Sebagai Label Field pada Form Inputan di VB6.Semoga artikel ini bermanfaat buat kita semua. Amin.
Selamat mencoba semoga sukses...


No comments: