By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,846 Members | 2,082 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,846 IT Pros & Developers. It's quick & easy.

TextBox LostFocus Event

P: n/a
I have some TextBoxes created by code.

I want to write a procedure to handle the lost of focus of any of these
TextBox.

How should I do that ?

Thanks

--
Bernard Bourée
be*****@bouree.net
Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Use AddHandler to add the common lostfocus event handler to all of your
textboxes.

Private Sub txtBoxLostFocusHandler(ByVal sender As Object, _
ByVal e As System.EventArgs)

End Sub

AddHandler TextBox1.LostFocus, AddressOf txtBoxLostFocusHandler
AddHandler TextBox2.LostFocus, AddressOf txtBoxLostFocusHandler
....
....

Also, if you are using the same lost focus event handler for all of the
textboxes on your form (or some other container such as a panel, tab page,
etc), you can do this within a loop:

' replace Me with whatever container you have your controls on
For Each txtBox As TextBox In Me.Controls
AddHandler txtBox.LostFocus, AddressOf txtBoxLostFocusHandler
Next txtBox
hope that helps..
Imran.
"Bernard Bourée" <be*****@bouree.net> wrote in message
news:ed**************@TK2MSFTNGP14.phx.gbl...
I have some TextBoxes created by code.

I want to write a procedure to handle the lost of focus of any of these
TextBox.

How should I do that ?

Thanks

--
Bernard Bourée
be*****@bouree.net

Nov 21 '05 #2

P: n/a
"Bernard Bourée" <be*****@bouree.net> schrieb:
I have some TextBoxes created by code.

I want to write a procedure to handle the lost of focus of any of these
TextBox.


Ooops... I misread your question. 'AddHandler'/'RemoveHandler' are the way
to go...

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #3

P: n/a
"Bernard Bourée" <be*****@bouree.net> schrieb:
I have some TextBoxes created by code.

I want to write a procedure to handle the lost of focus of any of these
TextBox.


\\\
Public Class FooBar
Inherits TextBox

Private Sub FooBar_GotFocus( _
ByVal sender As Object, _
ByVal e As System.EventArgs _
) Handles MyBase.GotFocus
Me.BackColor = Color.Yellow
End Sub

Private Sub FooBar_LostFocus( _
ByVal sender As Object, _
ByVal e As System.EventArgs _
) Handles MyBase.LostFocus
Me.BackColor = Color.White
End Sub
End Class
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #4

P: n/a
Thanks to Iram and Herfried !

-
Bernard Bourée
be*****@bouree.net
"Bernard Bourée" <be*****@bouree.net> a écrit dans le message de
news:ed**************@TK2MSFTNGP14.phx.gbl...
I have some TextBoxes created by code.

I want to write a procedure to handle the lost of focus of any of these
TextBox.

How should I do that ?

Thanks

--
Bernard Bourée
be*****@bouree.net

Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.