control types

G

Guest

im trying to write a global function to set controls up throughout a project.
ive managed to create a procedure to set the the basics on each form but
want to expand it to be able to set properties ie colours and text fonts for
each type of control on a form

ie

Public sub setControls( formName as form)
dim CtrlControl as Control
for each CtrlControl in formName.gettype
' what i want to do is a seclect function by each type
select Type
case button
case TextBox
etc
end select
next
end sub

can anybody explain how to do this please
 
C

Chris

Peter said:
im trying to write a global function to set controls up throughout a project.
ive managed to create a procedure to set the the basics on each form but
want to expand it to be able to set properties ie colours and text fonts for
each type of control on a form

ie

Public sub setControls( formName as form)
dim CtrlControl as Control
for each CtrlControl in formName.gettype
' what i want to do is a seclect function by each type
select Type
case button
case TextBox
etc
end select
next
end sub

can anybody explain how to do this please

Public sub setControls( Ctrls() as Control)
for each Ctrl as Control in Ctrls
' what i want to do is a seclect function by each type
select Typeof Ctrl
case is Button
case is TextBox
etc
end select
next
end sub

Calling from form:
public sub Form_Load(...) me.load
setControls(me.controls)
end sub

That's from memory but it's real close syntax wise.
 
A

Ahmed

Hi Peter,

What Chris wrote is correct. If you want to set specific properties
which are only exist for that control, you need to cast the control to
its original class.

For example
Public sub setControls( Ctrls() as Control)
for each Ctrl as Control in Ctrls
' what i want to do is a seclect function by each type
select Typeof Ctrl
case is Button
ctype(ctrl,button).someProperty = someValue.
case is TextBox
ctype(ctrl,textbox).someProperty = someValue.
 
C

Cyril Gupta

Hello,

I don't think casting is strictly necessary. If you have the control as type
object then you can change any property in it, and if that property exists
for the control it would work fine.

Of course casting would help you with intellisense.

Regards
Cyril Gupta
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top