Setting color of controls on runtime

Discussion in 'Questions (Windows Mobile)' started by RGS, Sep 7, 2008.

  1. RGS

    RGS Member Licensed User

    This fragement of code:

    Controls() = GetControls("frmMain")
    For i = 0 To ArrayLen(Controls())-1
    If ControlType(Controls(i)) = "Label" Then
    Control(Controls(i)).Color = cWhite
    End If

    does not seem to work in my application. During execution the error "If ControlType(Controls(i)) = "Label" Then Error Description: Object reference not set to an instance of an object" is raised.

    Types of controls on my form: TabControl, Labels, TextBox, Images and Listbox

    Am I overlooking something? Thanks in advance.
  2. moster67

    moster67 Expert Licensed User

    This works (it is just like your code - the only difference is that I declared the array in the Global-part).


    Sub Globals
    'Declare the global variables here.
       Dim controls(0)
    End Sub

    Sub App_Start
       Controls() = GetControls("frmMain")
    For i = 0 To ArrayLen(Controls())-1
    If ControlType(Controls(i)) = "Label" Then
    Control(Controls(i)).Color = cWHite
    End If

    End Sub
  3. specci48

    specci48 Well-Known Member Licensed User

    The problem is the TabControl!
    If I only used controls added by the designer, everything works fine (thats what moster67 surely did).
    But the ControlType statement doesn't work for the TabControl. I'll get an "Unable to evaluate expression." in the debug mode.

    I can't explain this behaviour because I'm not so familiar with the .Net and basic4ppc basics. Anyone? :sign0085:

  4. RGS

    RGS Member Licensed User

    Ah, that's it. That only leaves setting the color manually for each component. Thanks.
  5. Erel

    Erel Administrator Staff Member Licensed User

    This issue will be further checked.
    In the meantime you can use:
    Controls() = GetControls("form1")
    For i = 0 To ArrayLen(Controls())-1
    If [B]controls(i) <> ""[/B] AND ControlType(Controls(i)) = "Label" Then
    Control(Controls(i)).Color = cWhite
    End If
  6. RGS

    RGS Member Licensed User

    Thanks Erel for your kind help (and great product BTW!!!)
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice