473,408 Members | 1,826 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 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 21099
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: fmarchioni | last post by:
Hi all, I need to highlight textbox in a Form when they are selected. In order to do it I have added for each one a .GotFocus and .LostFocus Event Handler.... textRS.GotFocus += new ...
2
by: Robert W. | last post by:
I'm developing a WinForms app and have a slight problem that I hope someone can help me with. There are a series of textboxes that the user can enter information into. The text in these boxes is...
9
by: Jerry | last post by:
In limiting textbox input to 500 characters I would like to include a dynamic count of characters input while the user is typing into a textbox. This would obviously be a client side control,...
10
by: Dennis | last post by:
I have a simple form with one button and one text box. In the Form, I create an array list to track the events by adding a descriptive string item to the arraylist in each event. I first Click on...
2
by: Jonathan Allen | last post by:
In dialog boxes in Windows, the text in TextBox is automatically selected if you tab into the TextBox , but not when you select the TextBox using the mouse. What is the preferred way to support...
8
by: Martin | last post by:
Hi all, I'm trying to make a subclass of the Textbox. One of the things I did there is the following: Protected Overrides Sub OnLeave(ByVal e As System.EventArgs) If Me.DataType = 1 Or...
14
by: teddysnips | last post by:
WINDOWS FORMS I've a form that has a textbox that allows the user to enter a string. On the LostFocus event, the textbox formats the string into a preferred format. However, if the user...
5
by: =?Utf-8?B?QmVuIFIu?= | last post by:
Hi, In a .NET 2.0 winforms application, I've got a textbox that, when updated, uses the validated event to cascade the change to another textbox (along with another value). This works well if...
4
by: dbuchanan | last post by:
On the help page "TextBox Members" clearly there is an event for LostFocus. It is inherited from control. So without the event directly available for TextBox how do I use it? I know I could...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.