471,893 Members | 2,018 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,893 software developers and data experts.

TextBox LostFocus Event

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
4 20341
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
"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
"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
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.

Similar topics

4 posts views Thread by fmarchioni | last post: by
2 posts views Thread by Robert W. | last post: by
9 posts views Thread by Jerry | last post: by
10 posts views Thread by Dennis | last post: by
2 posts views Thread by Jonathan Allen | last post: by
5 posts views Thread by =?Utf-8?B?QmVuIFIu?= | last post: by
reply views Thread by zermasroor | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.