Home All Groups Group Topic Archive Search About
Author
11 Jun 2006 5:58 PM
Peter Newman
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

Author
11 Jun 2006 6:36 PM
Chris
Peter Newman wrote:
Show quoteHide quote
> 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.
Author
11 Jun 2006 8:29 PM
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

Chris wrote:
> 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.
Show quoteHide quote
>         etc
>     end select
>     next
> end sub
>
> Calling from form:
> public sub Form_Load(...) me.load
>     setControls(me.controls)
> end sub
>
Author
12 Jun 2006 2:56 AM
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
Author
12 Jun 2006 4:39 AM
Ahmed
You are right. If the array of type object there is no need for
casting.

Cyril Gupta wrote:
Show quoteHide quote
> 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