Thursday 23 August 2012

Textbox Control with TEXT in background


It would be better to create a custom TextBox control,
but here is something quickly hard-coded to give you a idea.

Find what event gives you desired result etc......


For simple example make sure textbox1 tabindex is not 1

Public Class Form1
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
TextBox1.ForeColor = Color.LightSlateGray
TextBox1.Text = "Enter Search Criteria"
End Sub
Private Sub TextBox1_Leave(sender As System.Object, e As System.EventArgs) Handles TextBox1.Leave
If TextBox1.Text = "" Then
            TextBox1.ForeColor = Color.LightSlateGray
TextBox1.Text = "Enter Search Criteria"
End If
End Sub
Private Sub TextBox1_Enter(sender As System.Object, e As System.EventArgs) Handles TextBox1.Enter
If TextBox1.Text = "Enter Search Criteria" Then
TextBox1.Text = ""
TextBox1.ForeColor = Color.Black
End If
End Sub
End Class

Output::
 

0 comments:

Post a Comment