Control by Name instead of Looping?

Is there a way to interact with a control by name? I know I can loop thru the Window.Control.

Is there a way I can work with Window.Control( theControlName )?


Thank you Dave!

Add dic as Dictionary to the window

In the window open event :

[code]Sub Open()
dic = new Dictionary
dic.value(“Rectangle1”) = Rectangle1

End Sub

In a button :

Sub Action() RectControl(dic.Value("Rectangle1")).Left = 100 End Sub

You can store all the controls that way upon open using the name of the control as key by looping with Window.Control.

Casting as Rectcontrol is OK for size and placement, but you will need more elaborate casting to interact with other properties.

This can be made into a method for easier access. just like you said.

extend window and add your own method for “control” and give it a string parameter and have it return a control or rectcontrol

GREAT idea Norm!

I’m using this :

[code]Function GetControlByName(aWindow as window, aName as String) As RectControl
dim ctrl as RectControl
dim i as Integer

For i=0 To aWindow.ControlCount-1
ctrl=RectControl( aWindow.control(i))
If ctrl.Name=aName Then
return ctrl
End If
return nil

End Function

[quote=189243:@jean-yves pochez] ctrl=RectControl( aWindow.control(i))
you might want to add

if control(i) isa rectcontrol

before casting it. If you have a timer or thread in there, you’ll get an illegalCastException