473,698 Members | 2,643 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 21195
Use AddHandler to add the common lostfocus event handler to all of your
textboxes.

Private Sub txtBoxLostFocus Handler(ByVal sender As Object, _
ByVal e As System.EventArg s)

End Sub

AddHandler TextBox1.LostFo cus, AddressOf txtBoxLostFocus Handler
AddHandler TextBox2.LostFo cus, AddressOf txtBoxLostFocus Handler
....
....

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.LostFocu s, AddressOf txtBoxLostFocus Handler
Next txtBox
hope that helps..
Imran.
"Bernard Bourée" <be*****@bouree .net> wrote in message
news:ed******** ******@TK2MSFTN GP14.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.EventArg s _
) Handles MyBase.GotFocus
Me.BackColor = Color.Yellow
End Sub

Private Sub FooBar_LostFocu s( _
ByVal sender As Object, _
ByVal e As System.EventArg s _
) Handles MyBase.LostFocu s
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******** ******@TK2MSFTN GP14.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
4566
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 EventHandler(gotFocus_Event); textName.GotFocus += new EventHandler(gotFocus_Event); textSurname.GotFocus += new EventHandler(gotFocus_Event); textAddress.GotFocus += new EventHandler(gotFocus_Event);
2
1619
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 only copied into the data model when the textbox's LostFocus event is fired. This has worked well so far. But I've just noticed that if the user enters some text into a textbox and then goes up to File-Save (on the parent form) that the newly...
9
10107
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, possibly a custom validator with a function written in javascript. Has anyone done this? Does someone have an example? Regards
10
3101
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 the Button then Click on the TextBox and enter an "a" then click on the Button again. The following is what I get for the event tracking Arraylist: but - GotFocus but - Clicked but - LostFocus txt - Changed
2
8032
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 this in VB/C# 2005? -- Jonathan Allen
8
4063
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 Me.DataType = 2 Then If IsNumeric(Me.Text) Then Me.TextAlign = HorizontalAlignment.Right End If
14
14605
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 presses the "Save" button while the textbox has the focus, the LostFocus code doesn't run at the right time, so that the "Save" function is dealing with an incorrectly formatted string and the whole caboodle goes splat.
5
7445
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 the user does indeed move the cursor to another textbox, but if the user clicks my "done" toolstripbutton after making a change in the textbox but without moving the cursor out, the validated event never fires. I have a pretty bad workaround where...
4
2307
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 create the event in code, but isn't there a more direct way?
0
8683
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9170
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8876
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7741
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6531
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5867
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4624
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2341
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.