PC Review


Reply
Thread Tools Rate Thread

How can I get the previous control?

 
 
Wael Soliman
Guest
Posts: n/a
 
      30th Mar 2004
I have many controls in the form I want to know which one lost the focus
(previous control)
For example:
In the form text1, text2, text3 and text4
The focus now in text1 and the user click by mouse on text3 the focus
now in text3 how can I know the last control is text1

Regards


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
 
 
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      30th Mar 2004
* Wael Soliman <(E-Mail Removed)> scripsit:
> I have many controls in the form I want to know which one lost the focus
> (previous control)
> For example:
> In the form text1, text2, text3 and text4
> The focus now in text1 and the user click by mouse on text3 the focus
> now in text3 how can I know the last control is text1


Something like 'Me.GetNextControl(Me.ActiveControl, False)'.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
 
Reply With Quote
 
Wael Soliman
Guest
Posts: n/a
 
      30th Mar 2004
Thanks for your response
But the GetNextControl return next control in the tab order; false to
search backward I want to get the last focused control before focus the
current one
Regards




*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
Cor
Guest
Posts: n/a
 
      30th Mar 2004
Hi Wael,

You did bring me on this idea, I saw no standard code, however this is very
generic for it.

I hope this helps?

Cor

\\\needs some controls which can have focus on a form
Dim last As String
Private Sub Form5_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
For Each ctr As Control In Me.Controls
AddHandler ctr.LostFocus, AddressOf meLostFocus
AddHandler ctr.GotFocus, AddressOf megotFocus
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
///


 
Reply With Quote
 
yououtthere
Guest
Posts: n/a
 
      30th Mar 2004
Wael,

Create a global variable to store a control in. Set the value of this
variable in the LostFocus event of the control.

HTH,

Geoff
"Wael Soliman" <(E-Mail Removed)> wrote in message
news:ugN%(E-Mail Removed)...
> I have many controls in the form I want to know which one lost the focus
> (previous control)
> For example:
> In the form text1, text2, text3 and text4
> The focus now in text1 and the user click by mouse on text3 the focus
> now in text3 how can I know the last control is text1
>
> Regards
>
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!



 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      30th Mar 2004
* "Cor" <(E-Mail Removed)> scripsit:
> \\\needs some controls which can have focus on a form
> Dim last As String
> Private Sub Form5_Load(ByVal sender As Object, _
> ByVal e As System.EventArgs) Handles MyBase.Load
> For Each ctr As Control In Me.Controls
> AddHandler ctr.LostFocus, AddressOf meLostFocus
> AddHandler ctr.GotFocus, AddressOf megotFocus
> Next
> End Sub


Nice idea. Notice that this will not work with nested controls. You
may want to loop though all controls recursively and add the handlers.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
 
Reply With Quote
 
Cor
Guest
Posts: n/a
 
      30th Mar 2004
Herfried,

> Nice idea. Notice that this will not work with nested controls. You
> may want to loop though all controls recursively and add the handlers.


And that do you send to me, what did I say about recursive and me, here the
next good idea, I had also some in other newsgroups and a lot more, watch my
mail (about my new website) tomorrow.

\\\
Dim last As String
Private Sub Form1_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
///

With this you can throw your hastable in my opinion in the disposing bin,

:-))

Cor


 
Reply With Quote
 
Cor
Guest
Posts: n/a
 
      30th Mar 2004
I mean ideas today of course.

:-))

Cor


 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      30th Mar 2004
* "Cor" <(E-Mail Removed)> scripsit:
> And that do you send to me, what did I say about recursive and me, here the
> next good idea, I had also some in other newsgroups and a lot more, watch my
> mail (about my new website) tomorrow.


:-)

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reference Previous control on subform from a Main form control tuesamlarry Microsoft Access Form Coding 3 19th Jul 2009 10:03 PM
You can't move to a previous control . . . =?Utf-8?B?RW1tYQ==?= Microsoft Access Form Coding 3 27th Jun 2006 02:51 PM
Previous tab control news.microsoft.com Microsoft Dot NET Framework Forms 1 22nd Mar 2005 12:13 PM
Why this is not returning to the previous control Tru Dixon Microsoft Access 3 12th Aug 2004 12:02 PM
Previous focused control Mikhail Fedosov Microsoft Dot NET Framework Forms 5 27th May 2004 10:58 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:06 PM.