Hi,
Is there a way to loop through EVERY control on a form (whether they
are directly on the form, or contained within children of the form)?
I would like to access the size and location of every control - at the
moment im just using a loop as:
For Each c As Control In Me.Controls
For Each cChild As Control In c.Controls
<...>
but this obviously only goes down one level - I could use a whole
series of nested loops, but performance and code readability are quite
important - is there a way to access (or directly loop through) all
the controls?
Thanks
Jamie 2 1395
You could use a recursive method,
The code is in C# but should be easily translated to VB.Net
private ArrayList GetAllChildCont rols(Control control)
{
ArrayList allControls = new ArrayList();
foreach(Control ctrl in control.Control s)
{
allControls.Add (ctrl);
allControls.Add Range(GetAllChi ldControls(ctrl ))
}
return allControls;
}
To use it simple call
ArrayList allControls = GetAllChildCont rols(myForm);
Sijin Joseph http://www.indiangeek.net http://weblogs.asp.net/sjoseph
Jamie Fraser wrote: Hi,
Is there a way to loop through EVERY control on a form (whether they are directly on the form, or contained within children of the form)?
I would like to access the size and location of every control - at the moment im just using a loop as:
For Each c As Control In Me.Controls
For Each cChild As Control In c.Controls
<...>
but this obviously only goes down one level - I could use a whole series of nested loops, but performance and code readability are quite important - is there a way to access (or directly loop through) all the controls?
Thanks
Jamie
Jamie,
See this sample I have sand some days ago in another newsgroup.
I hope this helps?
Cor
\\\\
Private Sub Form1_Load(ByVa l sender As Object, _
ByVal e As System.EventArg s) Handles MyBase.Load
doset(Me)
'It starts on a top place, can be any place by instance
'a button event, however for all controls it has to start with Me
End Sub
Private Sub doSet(ByVal thisCtr As Control)
Dim ctr As Control
'a placeholder for the reference of the object is created
For Each ctr In thisCtr.Control s
'The first time each (parent)control on a form
If TypeOf ctr Is Label
'Look if the "Control" is a label
ctr.text = "This you can do for every property from that label
End if
doSet(ctr)
'check if the control has children and do for that the same
Next
End Sub
/// Is there a way to loop through EVERY control on a form (whether they are directly on the form, or contained within children of the form)?
I would like to access the size and location of every control - at the moment im just using a loop as:
For Each c As Control In Me.Controls
For Each cChild As Control In c.Controls
<...>
but this obviously only goes down one level - I could use a whole series of nested loops, but performance and code readability are quite important - is there a way to access (or directly loop through) all the controls?
Thanks
Jamie This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Ryan Park |
last post by:
Hi,
//SITUATION
I got a panel control that hold a certain position on a form.
Every controls or UIs are on this panel.
At certain situation, I called dispose() method of this panel control
and change it with other panel which contains other business logic and
UI controls.
|
by: deko |
last post by:
I'm hoping someone can sanity check my understanding of the Object Model for
Forms/Controls. I'm having trouble drilling down into Control properties.
First, I have a record set with the following for a given Form:
1)Container
|
by: Wayne Aprato |
last post by:
I have a simple database which was originally written in Access 97.
When converted to Access 2000 file format it ran flawlessly in Access
2002. I've just tried to run it in Access 2003 and I am seeing the
following behaviour:
Some of the fields on the continuous main form which is a list of jobs
with their related details "flicker". While this is going on the form
seems to function as it should and isn't locked up. If I click and
hold...
|
by: Peter Frost |
last post by:
Please help
I don't know if this is possible but what I would really like to do is
to use On Error Goto to capture the code that is being executed when
an error occurs.
Any help would be much appreciated.
Thanks in advance
|
by: Yannick Turgeon |
last post by:
Hello,
We are in the process of examining our current main application. We have to
do some major changes and, in the process, are questionning/validating the
use of MS Access as front-end. The application is relatively big: around 200
tables, 200 forms and sub-forms, 150 queries and 150 repports, 5GB of data
(SQL Server 2000), 40 users.
I'm wondering what are the disadvantages of using Access as front-end? Other
that it's not...
| |
by: MS |
last post by:
Access 97 here.
I want a simple way to "lock" certain records on a form. Some records remain
"live" until all data is available which happens over time. When all the
fields are complete, I want the record to be able to be "locked", or
intentionally unlocked.
I thought of having a check box called "chkedit" that can be clicked when
the data entry for the record is complete. I have the following code in the
OnCurrent event for the...
|
by: TD |
last post by:
This is the code under a command button -
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.BackColor <> RGB(255, 255, 255) Then
ctl.BackColor = RGB(255, 255, 255)
End If
Next ctl
|
by: Neil |
last post by:
We are running an Access 2000 MDB with a SQL 7 back end. Our network guy is
upgrading to Windows Server 2003 and wants to upgrade Office and SQL Server
at the same time. We're moving to SQL Server 2005, and, since he already has
licenses for Office Pro 2002, he wants to upgrade to that.
I've been saying that we need to upgrade to Access 2003, not 2002, even if
Office is kept at 2002. We are also looking to do a fair amount of...
|
by: ApexData |
last post by:
I am considering building some distributable commercial applications.
For about a year now, I have been using Access2000. This was my first
venture into object oriented database development. Having a
background in Pascal and some C++, I would have preferred those
languages, but VBA made do. The SQL was fine.
I believe that Security issues on the backend, and data integrity/
corruption complaints over the network may be a stumbling...
|
by: Ron |
last post by:
Hi All,
I've recently installed a program written in Access 2000 on a laptop. The
laptop had an existing Office 2000 Pro which of course included Access. But
the program acts oddly (more oddly than I would have programmed, anyway).
On everyday controls, everything acts normally. But on some controls (and
they're always the same ones) the operator can't add or change data. Take a
birthday field as an example. If the client was born...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |