1
votes

I am trying to change the colour theme of an old VB6 application (make it look a bit more modern!).

Can someone tell me how I could change the backcolor of every control on a form without doing it for each and every control (label, button, frame etc!).

I have about 50 forms, all containing such controls and doing this manually for each form in code would take an age!

I am also open to better suggestions and ideas on how I can skin / theme a VB6 application?

Thanks in advance

5

5 Answers

6
votes

The .frm files are simply standard ANSI text files. A background color property of a control would look like this:-

BackColor       =   &H80000005&

(Note the above is a system color but you can specify the RGB color using by using the lower 3 bytes and leaving the high byte 0).

A control such a Label would look like this:-

Begin VB.Label Label1 
  Caption         =   "Hello:"
  Height          =   285
  Left            =   90
  TabIndex        =   3
  Top             =   480
  Width           =   1305
End

So that task could be done lexically by parsing the .frm files and inserting (or replacing) the BackColor attribute line.

Edit:

Useful link posted in comments by MarkJ : Form Description Properties

5
votes

You can do a for each and eliminate the controls you don't want.

Dim frmThing as Form    
Dim ctlThing as Control

For Each frmThing In Forms
  frmThing.BackColor = vbYellow
  For Each ctlThing In frmThing.Controls
    If (TypeOf ctlThing Is TextBox) Or _
    (TypeOf ctlThing Is CheckBox) Or _
    (TypeOf ctlThing Is ComboBox) Then
      ctlThing.BackColor = vbYellow
    End If
  Next
Next
1
votes

you could do this at runtime by looping the Controls collection and setting the background of each. This would give you the flexibility of changing your theme.

You could also work through the source files, parse out the controls and enter/change the background colours that you want. This approach is probably more work, for less reward.

1
votes

Just for completeness...

ssCheck does not have a BackColor property and will produce an error using the aforementioned methods

~Mike~

0
votes

It's going back quite a few years now, but wasnt there a 'Transparent' background color?

Set all the labels to have a transparent background, and you only need to set the form color once.