Results 1 to 7 of 7

Thread: Changing backcolor on all controls.

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2000
    Location
    Boulder, Colorado
    Posts
    22
    I can't figure it out. Please help me. I would like the user to be able to change the backcolor of all forms and controls (i.e., command buttons, labels, etc.) by selecting a color from the Common Dialog control (ShowColor). frmMain has a menu option to change the forms' backcolor and forecolor. How do implement this in code? I know how to do it on the same form, but how do I have it affect all forms and controls within the application????
    C-Dog

  2. #2
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    617

    Could be wrong

    If you want to do this at run time...

    (I could be wrong)

    But I'd write a function that takes a form, and a color
    as argument and
    load the form (at start of app) (Don't Have to show it)
    go thru all the controls on each of the forms and change the backcolor to the desired color

    One note though:

    For command buttons... You have to set the style to 'Graphical' before doing that


  3. #3
    Lively Member
    Join Date
    Jul 2000
    Location
    Ca
    Posts
    106
    this might work

    Code:
    comondialog1.showcolor
    Dim MyControl As Control
    
    For Each MyControl In form1.Controls
      MyControl.backcolor = commondialog1.color  
    Next
    hope that helps...

  4. #4
    Guest
    You would need to loop through all Forms.
    Code:
    Dim frm As Form
    Dim ctl As Control
    
    For Each frm In Forms
        For Each ctl In frm.Controls
            If TypeOf ctl Is CommandButton Then ctl.BackColor = vbBlue
        Next ctl
    Next frm

  5. #5
    Addicted Member
    Join Date
    Aug 1999
    Location
    Ilirska Bistrica, Slovenia
    Posts
    242
    But this method doesn't work for all controls (I know it doesn't work for CommandButtons).
    I've found some code about changing commandbutton's back color at www.vbaccelerator.com (I don't know exact URL) and I think it can be modified to change back colors of other controls, too.
    Zvonko Bostjancic
    Ilirska Bistrica, Slovenia
    [email protected]
    Using VS6 Professional with SP3
    Programming mostly in VB and I've started to learn VC++ & MFC

  6. #6
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    You can change the background color of a CommandButton but it won't show unless you set it's Style property to 1 - Graphical.

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Jul 2000
    Location
    Boulder, Colorado
    Posts
    22

    Talking Success at last!!

    Thanks to everyone who responded. You were all very helpful.
    C-Dog

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