469,575 Members | 1,574 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,575 developers. It's quick & easy.

Lost Focus

How do I connect to an event being thrown when a field has
lost focus? Could you please give a code example?
--
Patrick De Ridder
ng****@freeler.nl
Nov 15 '05 #1
6 27968
>>>>> "Patrick" == Patrick De Ridder <ng****@freeler.nl> writes:

Patrick> How do I connect to an event being thrown when a field has
Patrick> lost focus? Could you please give a code example?

WinForm or WebForm?

--
Peter Wu
Powered by Microsoft Windows XP [Version 5.1.2600]
Nov 15 '05 #2
mk
For a windows application:

[Assuming that you wish to receive LostFocus notification
for a textbox called textBox1]

Create a method as follows:

private void textBox1_LostFocus(object sender,
System.EventArgs e)

Add the following to InitializeComponent():

this.textBox1.LostFocus += new System.EventHandler
(this.textBox1_LostFocus);

HTH,

mk

-----Original Message-----
How do I connect to an event being thrown when a field haslost focus? Could you please give a code example?
--
Patrick De Ridder
ng****@freeler.nl
.

Nov 15 '05 #3
Hi mk,

Your solution to signify the loss of focus of a text box works fine !
Many thanks.
--
Patrick De Ridder
ng****@freeler.nl
Nov 15 '05 #4
100 <10*@100.com> wrote in message
news:Og**************@tk2msftngp13.phx.gbl...
Hi Patric,

A bunch of events are fired when the control loses the focus.
The right order is:
Leave
Validating
Validated
LostFocus

According to the event order above. You will receive LostFocus only if the
focus is actually lost and Leave as a inforamtion when request for changing the focus has arrived. Validating event handler can cancel the request and
it is posible to receive Leave, but not to receive LostFocus.

Anyway there is a bug in the framework and this order is valid only when the focus has been chaged using the TAB key to circle among the controls. If you use the mouse for changing the focus (which is most often used I think) the event order is:
LostFocus
Leave
Validating
Validated

You can see that you will receive LostFocus first and then the others
events. Validating event handler can cancel the operation and the focus
won't be changed even though you have received LostFocus.
So, the LostFocus is not reliable.
I haven't seen good workaround for this bug. Some people suggest catching
Windows messages, other using some special flags inside the form class. But I think there is no universal cure for this. Until MS don't fix this the
best workaround depends on the application logic.


Hi 100,

This is very interesting. However, what you
write is not totally within the scope of my
understanding at this point in time. Are
there any references for me to look at
on what you are discussing?

I have applied what mk advised me to do,
and that works fine.So I am very pleased.

Greetings,
--
Patrick De Ridder
bg****@freeler.nl
Nov 15 '05 #5
100
Hi Patric,
I have applied what mk advised me to do,
and that works fine.So I am very pleased.

This is the right way to do it. I just warned you about a well known bug in
the framework.
As long you don't do any validation of the data typed in text boxes It will
be fine. I just mantioned it just in case you are going to use validating
event. If you use LostFocus and Validating event together you will
definitely run into this.

B\rgds
100

Nov 15 '05 #6
On Mon, 11 Aug 2003 20:39:55 +0200, "Patrick De Ridder"
I will read up on validation, since that appears to be your main concern,
and I will have been warned by you not to combine it with the focus stuff.
Actually I do quite a bit of data validation (my code) in the prig, alerting
the user in the case of incorrect prig use with message boxes. Should I
understand from you that there are better alternatives to this approach?

Sorry prig = prog(gram)
(Typo)
--
Patrick De Ridder
ng****@freeler.nl

Nov 15 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Ellis Yu | last post: by
reply views Thread by =?Utf-8?B?Qw==?= | last post: by
1 post views Thread by =?Utf-8?B?amFtZXNAbm9zcGFtLmNvbQ==?= | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.