getting the last control in focus

  • Thread starter Thread starter Sameh Ahmed
  • Start date Start date
S

Sameh Ahmed

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
 
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
 
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
///
 
* "Sameh Ahmed said:
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.
 
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
 
Back
Top