469,593 Members | 1,984 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

getting the last control in focus

Hello there
Is there a way to get the last control that was in focus before the current
control?
please note that I don't want the next or previous control in the tab order,
I need the last one used by the user.
Thanks in advance.
Regards
Sameh
Nov 20 '05 #1
4 5033
Hi Sameh,

I do not know if that is standard on the other hand in my opinion is it not
to difficult to make
When you build a general lost focus event than you can set the last control
name in that.
Than you know always what was the last.

Just a thought I do not remember it if I ever did tried it.

Cor
Hello there
Is there a way to get the last control that was in focus before the current control?
please note that I don't want the next or previous control in the tab order, I need the last one used by the user.
Thanks in advance.
Regards
Sameh

Nov 20 '05 #2
Hello Cor
may I ask what do you mean by a general focus event, how do you do that?
it will be a hell of a job to create a lost focus event for every control on
each form!
Thanks for your time
Regards
Sameh
"Cor Ligthert" <no**********@planet.nl> wrote in message
news:uM**************@TK2MSFTNGP09.phx.gbl...
Hi Sameh,

I do not know if that is standard on the other hand in my opinion is it not to difficult to make
When you build a general lost focus event than you can set the last control name in that.
Than you know always what was the last.

Just a thought I do not remember it if I ever did tried it.

Cor
Hello there
Is there a way to get the last control that was in focus before the

current
control?
please note that I don't want the next or previous control in the tab

order,
I need the last one used by the user.
Thanks in advance.
Regards
Sameh


Nov 20 '05 #3
Hi Sameh,

Fool I am, it is my standard sample for setting dynamicly handlers.
Set some textboxes than you see everytime the name in the last.

I hope this helps?

Cor

\\\
Dim last As String
Private Sub Form5_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
doset(Me)
End Sub
Private Sub doSet(ByVal parentCtr As Control)
Dim ctr As Control
For Each ctr In parentCtr.Controls
AddHandler ctr.LostFocus, AddressOf meLostFocus
AddHandler ctr.GotFocus, AddressOf meGotFocus
doSet(ctr)
Next
End Sub
Private Sub meLostFocus(ByVal sender As Object, _
ByVal e As System.EventArgs)
last = DirectCast(sender, Control).Name
End Sub
Private Sub meGotFocus(ByVal sender As Object, _
ByVal e As System.EventArgs)
DirectCast(sender, Control).Text = last
End Sub
///
Nov 20 '05 #4
* "Sameh Ahmed" <es******@hotmail.com> scripsit:
Is there a way to get the last control that was in focus before the current
control?
please note that I don't want the next or previous control in the tab order,
I need the last one used by the user.


Recursively loop through the controls and add a handler to their
'LostFocus' event. This handler will receive the event for all
controls. Inside the handler, you can cast 'sender' to 'Control' and
assign it to a private member.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

303 posts views Thread by mike420 | last post: by
1 post views Thread by clickon | last post: by
4 posts views Thread by Jon Slaughter | last post: by
2 posts views Thread by =?Utf-8?B?VmFuZXNzYQ==?= | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.