Update Textbox when focus lost

Meanie

Newcomer
Joined
Jan 4, 2003
Messages
23
How can I go about updating a textbox when the focus on this textbox is lost?

For instance, if the user clears the textbox, I want the default value to be entered when the user clicks away.
 
Try a MouseLeave event.

Private Sub TextBox1_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.MouseLeave
if TextBox1.Text = "" then
TextBox1.Text = "Anything"
end if
End Sub

This will leave Anything in the box if it is empty.

I hope that helped.
Dan
 
Thanx for the help, but the code really doesn't do much if the mouse is moved before the textbox is made blank or if the user TABs between the controls instead of using the mouse.
 
You beat me to the reply, I was just going to update this replay to mention that. Sorry

Visual Basic:
    Private Sub TextBox1_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.Leave
        If TextBox1.Text = "" Then
            TextBox1.Text = "Anyhing"
        End If
    End Sub

This will update the textbox if another is in focus.
 
Last edited by a moderator:
Back
Top