Results 1 to 5 of 5

Thread: Change all form props at once?

  1. #1

    Thread Starter
    Lively Member jonvantuyl's Avatar
    Join Date
    Nov 2000
    Location
    Michigan
    Posts
    75

    Question

    i was wondering if there is any way to change all the forms background colors and label colors (inside one program) when somebody hits a command button?

  2. #2

  3. #3
    Lively Member
    Join Date
    Jul 2000
    Location
    Lost in the Mojave Desert
    Posts
    82
    iknow there is a controls collection does the same apply with forms as part of the program? if this is possible then the code is small but if not then depending on how many controls,forms and properties you want to manipulate it could take a lot of code, basically yes is the answer
    Don't go away mad, just go away.

    Bam-Bam

  4. #4
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    Add 3 forms to a project, 2 labels on each form, and a command button on form1.

    Code:
    Private Sub Form_Load()
        
        ' Display all forms
        Load Form2
        Form2.Show
        Load Form3
        Form3.Show
        
    End Sub
    
    
    Public Sub Command1_Click()
        Dim f As Form, c As Control
        
        ' Get Form Object from Collection of Forms
        For Each f In Forms
            
            ' Change Backcolor as form to a Random Color
            f.BackColor = RGB(Rnd * 255, Rnd * 255, Rnd * 255)
            
            ' Will loop through every kind of control currently on form
            For Each c In f.Controls
                
                ' Determine is current control is a Label
                If TypeOf c Is Label Then
                
                    'Change BackColor property to a Random Color
                    c.BackColor = RGB(Rnd * 255, Rnd * 255, Rnd * 255)
                    
                End If
                
            Next c
            
        Next f
        
    End Sub
    Good Luck
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  5. #5
    Member
    Join Date
    May 2000
    Location
    Boston, MA
    Posts
    52
    Is this what you need?
    Code:
    Dim Form as Form
    
    For Each Form in Forms
         Form.BackColor = vbRed
    Next
    You can put similar code for controls in the form's paint event, but it would be better suited for its own subroutine you could call after changing the color....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width