By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,822 Members | 1,038 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,822 IT Pros & Developers. It's quick & easy.

How to get the last active control

P: n/a
Any equivalent to VB's PreviousControl in VB.NET?

Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies

P: n/a
Hi,

Probably there is a much better way, when not, than you can maybe try this
sample I created.

\\\\Needs by instance a form with two textoboxes and surely one button and
pasting this code in
Private PreviousControl As Control
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.Leave, AddressOf meLeave
doSet(ctr)
Next
End Sub
Private Sub meLeave(ByVal sender As Object, _
ByVal e As System.EventArgs)
PreviousControl = DirectCast(sender, Control)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
MessageBox.Show(PreviousControl.Text)
End Sub
///

I hope this helps,

Cor
Nov 21 '05 #2

P: n/a
Cor,

Thanks for the code. It does help. Just one comment: it seems to me that
the call to doSet(ctr) in the For Each loop in Sub doSet is redundant.
Don't you think so?

--
Sent via .NET Newsgroups
http://www.dotnetnewsgroups.com
Nov 21 '05 #3

P: n/a
Amnon,
Just one comment: it seems to me that the call
to doSet(ctr) in the For Each loop in Sub doSet is redundant.
Don't you think so?


No normally it is not.
It is a recursive method.
It gets as well all the controls that are in another control.

However if you are sure that you have placed your controls only direct on
your form. Than it is redundant.

I hope this gives the idea?

Cor
Nov 21 '05 #4

P: n/a
Yes, Thanks. This answers my question.

--
Sent via .NET Newsgroups
http://www.dotnetnewsgroups.com
Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.