Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / October 2004

Tip: Looking for answers? Try searching our database.

TextBox LostFocus Event

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bernard Bour?e - 23 Oct 2004 18:22 GMT
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

Signature

Bernard Bour?e
bernard@bouree.net

Imran Koradia - 23 Oct 2004 19:29 GMT
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.

>I have some TextBoxes created by code.
>
[quoted text clipped - 4 lines]
>
> Thanks
Herfried K. Wagner [MVP] - 23 Oct 2004 19:53 GMT
"Bernard Bour?e" <bernard@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
///

Signature

Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/

Herfried K. Wagner [MVP] - 23 Oct 2004 19:54 GMT
"Bernard Bour?e" <bernard@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...

Signature

Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/

Bernard Bour?e - 24 Oct 2004 00:01 GMT
Thanks to Iram and Herfried !

-
Bernard Bour?e
bernard@bouree.net
> I have some TextBoxes created by code.
>
[quoted text clipped - 4 lines]
>
> Thanks

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.