Artikel kali Admin akan berbagi sebuah kode vb6 yaitu bagaimana cara membuat Teks Placeholder dengan vb6.
Teks Placeholder adalah teks sementara yang di tampilkan dalan kotak teks isian dengan warna transparant tempat dimana user akan mengisi atau menginput data.
Teks Placeholder juga digunakan sebagai petunjuk atau keterangan mengenai jenis data inputan.
Untuk lebih jelasnya tentang Teks Placeholder perhataikan gambar dibawah ini :
Teks Placeholder |
Untuk membuat koatak Teks Placeholder menggunakan vb6 sangatlah mudah Anda cukup menambahkan 2 TextBox saja pada Form.
Untuk desain perhatikan gambar diatas, kemudian ketikan kode dibawah ini :
Option Explicit
Private Const PlaceholderText1 As String = "Enter your Email here..."
Private Const PlaceholderText2 As String = "Enter your Password here..."
Private Const PlaceholderColor As Long = vbGrayText ' Warna teks placeholder
Private Const NormalTextColor As Long = vbWindowText ' Warna teks normal
Private Sub Form_Activate()
Text1.SetFocus
End Sub
Private Sub Form_Load()
' Set the initial placeholder
SetPlaceholder1 Text1
SetPlaceholder2 Text2
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
' Remove placeholder when TextBox receives focus
If Text1.Text = PlaceholderText1 Then
Text1.Text = ""
Text1.ForeColor = NormalTextColor
End If
End Sub
Private Sub Text1_LostFocus()
' Set placeholder when TextBox loses focus and is empty
If Text1.Text = "" Then
SetPlaceholder1 Text1
End If
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
' Remove placeholder when TextBox receives focus
If Text2.Text = PlaceholderText2 Then
Text2.Text = ""
Text2.ForeColor = NormalTextColor
End If
End Sub
Private Sub Text2_LostFocus()
' Set placeholder when TextBox loses focus and is empty
If Text2.Text = "" Then
SetPlaceholder2 Text2
End If
End Sub
Private Sub SetPlaceholder1(txtBox1 As TextBox)
txtBox1.Text = PlaceholderText1
txtBox1.ForeColor = PlaceholderColor
End Sub
Private Sub SetPlaceholder2(txtBox2 As TextBox)
txtBox2.Text = PlaceholderText2
txtBox2.ForeColor = PlaceholderColor
End Sub
No comments:
Post a Comment