473,725 Members | 1,787 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Iterate through controls on form in design view...

Hi
In Microsoft Access it is possible to write code like this

Sub test()
DoCmd.OpenForm "TestForm", acDesign
Dim a As Control
For Each a In Forms("TestForm ").Controls
Do stuff
Next
End Sub

To iterate through all controls on a form at DESIGN time. This will then
take effect for the form at runtime.

Is this possible in VB.Net?
Best regards

Jan
Nov 20 '05 #1
14 4037
Hi Jan,

I'm a bit confused by what you mean by doing stuff at design-time to take
effect at run-time so the following is more for info than to answer your
query.

In .NET a Control's constructor is called both at design-time and (of
course) at run-time. There is a flag, Control.DesignM ode which tells you
which.

If you want to do something for literally <all> the Controls on the Form,
you'll have to have a recursive method which takes a Control as a parameter
and does something for each of its contained Controls and so on for theirs. (A
Form is a Control so no problem getting it all started).

Class Foo As Form
Public Sub New()
MyBase.New()
InitializeCompo nent()
If Me.DesignMode Then
DoStuffToContro ls (Me)
End If
End Sub

Sub DoStuffToTheCon trolsOf (oControl As Control)
For Each oChildControl in oControl.Contro ls
Do stuff to oChildControl
DoStuffToTheCon trolsOf (oChildControl)
Next
End Sub

Regards,
Fergus
Nov 20 '05 #2
Hi Fergus
Thanks for your answer.
What I meant was that you can move create a form and place some controls on
it. Then "normally" af runtime the controls will be placed at the same place
as at design time. But you can move the controls via code and then the
design view and the runtime view are different.

What I would like to do was to edit properties in design time via code (ie
size of all textboxes)
Thus permanently changing the look of the form in design view.

Your code confuses me a bit:
You seem to have two different functions
DoStuffToContro ls
and
DoStuffToTheCon trolsOf
Should this be the same function?
Also in
Sub DoStuffToTheCon trolsOf (oControl As Control)
For Each oChildControl in oControl.Contro ls
Do stuff to oChildControl
DoStuffToTheCon trolsOf (oChildControl)
Next
End Sub
Where do you define the oChildControl?
Best regards

Jan

"Fergus Cooney" <fi******@tesco .net> skrev i en meddelelse
news:uG******** ******@TK2MSFTN GP11.phx.gbl... Hi Jan,

I'm a bit confused by what you mean by doing stuff at design-time to take effect at run-time so the following is more for info than to answer your
query.

In .NET a Control's constructor is called both at design-time and (of
course) at run-time. There is a flag, Control.DesignM ode which tells you
which.

If you want to do something for literally <all> the Controls on the Form, you'll have to have a recursive method which takes a Control as a parameter and does something for each of its contained Controls and so on for theirs. (A Form is a Control so no problem getting it all started).

Class Foo As Form
Public Sub New()
MyBase.New()
InitializeCompo nent()
If Me.DesignMode Then
DoStuffToContro ls (Me)
End If
End Sub

Sub DoStuffToTheCon trolsOf (oControl As Control)
For Each oChildControl in oControl.Contro ls
Do stuff to oChildControl
DoStuffToTheCon trolsOf (oChildControl)
Next
End Sub

Regards,
Fergus

Nov 20 '05 #3
Hi again Fergus
I also do not see how you call the function.
If I hit F5 the form is not in design mode anylonger.

Best regards

Jan


"Fergus Cooney" <fi******@tesco .net> skrev i en meddelelse
news:uG******** ******@TK2MSFTN GP11.phx.gbl...
Hi Jan,

I'm a bit confused by what you mean by doing stuff at design-time to take effect at run-time so the following is more for info than to answer your
query.

In .NET a Control's constructor is called both at design-time and (of
course) at run-time. There is a flag, Control.DesignM ode which tells you
which.

If you want to do something for literally <all> the Controls on the Form, you'll have to have a recursive method which takes a Control as a parameter and does something for each of its contained Controls and so on for theirs. (A Form is a Control so no problem getting it all started).

Class Foo As Form
Public Sub New()
MyBase.New()
InitializeCompo nent()
If Me.DesignMode Then
DoStuffToContro ls (Me)
End If
End Sub

Sub DoStuffToTheCon trolsOf (oControl As Control)
For Each oChildControl in oControl.Contro ls
Do stuff to oChildControl
DoStuffToTheCon trolsOf (oChildControl)
Next
End Sub

Regards,
Fergus

Nov 20 '05 #4
Hi Jan,

The two names should be the same - that's an oops on the editing - so you
call it from Sub New() as shown.

oChildControl is, guess what, a Control!! ;-)

When you hit F5 I would certainly hope that you are no longer in Design
mode! But why does this matter?

!! What I would like to do was to edit properties in design time
!! via code (ie size of all textboxes)
!! Thus permanently changing the look of the form in design view.

I'm afraid this still makes no sense to me. Do you mean that you want, for
example, all TextBoxes to be 200 pixels wide, regardless of the setting in the
properties box? If so, why would you want this at design time but not at run
time?? Or do you want it for both? What is supposed to happen if you drag a
new TextBox onto the Form?

!! But you can move the controls via code and then the
!! design view and the runtime view are different.

Could you say what you actually want to do because I'm finding it hard to
create an imaginary situation.

Regards,
Fergus
Nov 20 '05 #5
Hi again Fergus
Thanks for your time
I will try to explain further.

I wanted to move all my controls on my form up 23 pixels if the
Control.Locatio n.Y was bigger than 150
Something like
if MyControl.Locat ion.Y > 150 then mycontrol.locat ion.Y -= 23

I can do this at runtime (which means that my form has a different look in
design time than it has in runtime).
But I would like to do this in code while the form is in Design mode. This
should free me from moving the controls manually with the mouse or using the
Properties Window.

Hope this makes sense.

Jan


"Fergus Cooney" <fi******@tesco .net> skrev i en meddelelse
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Hi Jan,

The two names should be the same - that's an oops on the editing - so you call it from Sub New() as shown.

oChildControl is, guess what, a Control!! ;-)

When you hit F5 I would certainly hope that you are no longer in Design mode! But why does this matter?

!! What I would like to do was to edit properties in design time
!! via code (ie size of all textboxes)
!! Thus permanently changing the look of the form in design view.

I'm afraid this still makes no sense to me. Do you mean that you want, for example, all TextBoxes to be 200 pixels wide, regardless of the setting in the properties box? If so, why would you want this at design time but not at run time?? Or do you want it for both? What is supposed to happen if you drag a new TextBox onto the Form?

!! But you can move the controls via code and then the
!! design view and the runtime view are different.

Could you say what you actually want to do because I'm finding it hard to create an imaginary situation.

Regards,
Fergus

Nov 20 '05 #6
Hi Jan,

I understand now. You want to be doing this at design-time <and> at
run-time. In this case there's no need for checking DesignMode.

When you load a Form at design-time, the constructor is called. You can
use the function that I gave you to do the check-and-move and you'd call it
from Sub New after the call to ComponentInitia lize.

If you have any problems with it, show me how you are using the code and
we'll take it from there.

Regards,
Fergus
Nov 20 '05 #7
Jan
Jan,

In VS2003 you don't have to remove one control at a time. You can select
all controls (Ctrl-A) and all will move the same amount. This might even be
easier than writing code.

Regards,
Jan

"Jan Nielsen" <Re************ **@tiscali.dk> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
Hi again Fergus
Thanks for your time
I will try to explain further.

I wanted to move all my controls on my form up 23 pixels if the
Control.Locatio n.Y was bigger than 150
Something like
if MyControl.Locat ion.Y > 150 then mycontrol.locat ion.Y -= 23

I can do this at runtime (which means that my form has a different look in
design time than it has in runtime).
But I would like to do this in code while the form is in Design mode. This
should free me from moving the controls manually with the mouse or using the Properties Window.

Hope this makes sense.

Jan


"Fergus Cooney" <fi******@tesco .net> skrev i en meddelelse
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Hi Jan,

The two names should be the same - that's an oops on the editing -
so you
call it from Sub New() as shown.

oChildControl is, guess what, a Control!! ;-)

When you hit F5 I would certainly hope that you are no longer in Design
mode! But why does this matter?

!! What I would like to do was to edit properties in design time
!! via code (ie size of all textboxes)
!! Thus permanently changing the look of the form in design view.

I'm afraid this still makes no sense to me. Do you mean that you

want, for
example, all TextBoxes to be 200 pixels wide, regardless of the setting
in the
properties box? If so, why would you want this at design time but not at run
time?? Or do you want it for both? What is supposed to happen if you

drag a
new TextBox onto the Form?

!! But you can move the controls via code and then the
!! design view and the runtime view are different.

Could you say what you actually want to do because I'm finding it
hard to
create an imaginary situation.

Regards,
Fergus


Nov 20 '05 #8
Hi Jan,

LOL!! Indeed. ;-)

Regards,
Fergus
Nov 20 '05 #9
Cor
LOL
Nov 20 '05 #10

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

Similar topics

2
1748
by: Paul | last post by:
I've searched this site for a few hours without a solution to my problem. Please help~ In short, the controls on my form have vanished. I can see nothing but a gray screen and grayed out navigator buttons on the lower left of the form, with no record count (118 records) to the right of the navigator buttons as I am used to seeing. The record source of this form is set to tbl_Employees. This table has 118 records as verified by opening...
10
2701
by: BBM | last post by:
Hi, I have been developing with C# User Controls and occasionally have a problem where I "lose" a control from the design surface of the User Control. The controls that I am using to build my User Controls are themselves custom controls. Occasionally, when I change something in either the User Control and/or one of the custom controls that are on it and recompile, when I go to the "Visual" design surface of the User Control, the...
0
2227
by: Frnak McKenney | last post by:
I'm running into problems with VisualStudio.NET2003 and Windows Forms inheritance. It _feels_ like a bug, but it could just as well be a misunderstanding on my part regarding how the VS Designer handles inheritance. Environment: OS Name Microsoft Windows 2000 Professional Version 5.0.2195 Service Pack 4 Build 2195 Microsoft Visual C# .NET
4
2413
by: Boban Dragojlovic | last post by:
I create a new webform (I always use codebehind), and I insert some server-side controls into the form (the ASPX) Later, I switch to codeview, and I notice that some (sometimes all) of the controls I created have been automatically defined for me in the #Region " Web Form Designer Generated Code " section Later, when I add more controls this no longer happens. First, I'm wondering which of my actions causes it to no longer do this;
6
436
by: Nathan Sokalski | last post by:
I am trying to dynamically add controls to my page, but am having trouble with controls such as buttons. I have been able to add simple controls such as Label controls, because they can be placed anywhere. I have managed to add Labels using the following code: Dim extralabel As Label = New Label extralabel.Text = "Generated Label" Me.Controls.Add(extralabel)
4
6586
by: romy | last post by:
Hi In VB.net I have a set of linkButtons controls in a form , which I want to iterate on them and change their text property. How it's done ? thanks
1
251
by: Nadav | last post by:
hello, I have a form, with some controls I decided to define as static. Every time I change something in the form's design, InitializeComponent() is re-written and screws up the static definitions. If I take the code of these controls out of that function, I don't see them in the design view of the form and I cant have that. Is there a way to set them static and also view them in the design view ? (There's no "Static" in "Modifiers"...
20
12420
by: Steve | last post by:
What is the code to create a list of the controls on a closed form in the current database? Thanks! Steve
1
2337
by: =?Utf-8?B?UmljaA==?= | last post by:
I removed a form and all its associated files (designer, vb, resx) from a project because I was having a problem with that form. I copied these files to another folder away from the project folder. The problem turned out not to be with that form. I fixed the problem and copied the files of the removed form back to the project folder and re-added these files back to the project. When I run the project - the form shows up with all of its...
0
8886
marktang
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...
0
9257
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9171
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9108
tracyyun
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...
0
8093
agi2029
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...
1
6702
isladogs
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...
0
6010
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();...
0
4514
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...
2
2632
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.