473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to get the last active control

Any equivalent to VB's PreviousControl in VB.NET?

Nov 21 '05 #1
4 5947
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
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
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
Yes, Thanks. This answers my question.

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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Pierre Mengal | last post by:
Active Up is pleased to announce the release of 3 new products. All these products are now part of the Web.Controls Suite . The products featured in the package are: Active Image ..NET...
3
by: Robert Neville | last post by:
How do you return the last Active Control when the control is on a tab control? Screen.ActiveControl does not seem to work. Here's the statement that my code uses. Set ctlOld =...
1
by: Dave | last post by:
Hi, I have an active x control that been createted when i drop it on a win form and sent event to the form event function(like button click event for button control or so), This active x send...
0
by: Kannan | last post by:
My application is an MFC application but since MFC is essentially a Object Oriented wrapper for Win32 I am taking the liberty to post my question here. I also must confess that I am not an Active X...
1
by: Morten Snedker | last post by:
Just for the sake of learning, I'm trying to make a simple Active-X in VB.NET. It should contain the MonthCalendar control, a date should be picked, and the Active-X control would return the...
5
by: Mike | last post by:
I have been using an Active X control(SFrmAx52.ocx) in my Access program without problem in the past. However now I can see the control(SFrmAx52.ocx) in my System 32 folder, I see the control...
4
by: Sarita Sai Bhushan | last post by:
Hi, While I was developing a active desktop web page in ASP.Net using server controls I faced a problem with the autopostback property of server control. The sever control I used in my aspx page...
2
by: arthur.dayton | last post by:
I am using Access 2007. I'm trying to set the control on a subform to the current time. My code is: Private Sub Command7_Click() With Me. ..Form.SetFocus ..Form!.SetFocus RunCommand...
7
by: Andrus | last post by:
I have UserControls in MDI child forms containing TextBoxes and other controls. When user re-activates form, I need that Control which was last activated is activated again. Currently *first*...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.