Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

  • *Experts*
Posted

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

Member, in good standing, of the elite fraternity of mentally challenged programmers.

 

Dolphins Software

Posted
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.
  • *Experts*
Posted (edited)

You beat me to the reply, I was just going to update this replay to mention that. Sorry

 

   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.

Edited by divil

Member, in good standing, of the elite fraternity of mentally challenged programmers.

 

Dolphins Software

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...