Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21096

[RESOLVED] Colour background of controls and forms forms throughout app without specifying name

$
0
0
Hi,

I have this code to set all forms and controls in my program to a colour of my choosing.

vb Code:
  1. Public Sub colour()
  2.   Static lngCustom(15) As Long
  3. Static lngCurrent As Long
  4. Dim lngHandle As Long
  5. Dim lngResult As Long
  6. Dim uCol As CHOOSECOLOR
  7. 'Apply colour to forms
  8.  uCol.lStructSize = Len(uCol)
  9. uCol.hwndOwner = frmMain.hwnd
  10. uCol.lpCustColors = VarPtr(lngCustom(0))
  11. uCol.rgbResult = lngCurrent
  12. uCol.Flags = CC_FULLOPEN Or CC_RGBINIT
  13. lngResult = CHOOSECOLOR(uCol)
  14.    If uCol.rgbResult = vbBlack Then Exit Sub
  15.   For Each objForm In Forms
  16.      If lngResult <> 0 Then
  17.        'Customise the colour of the program
  18.        objForm.BackColor = uCol.rgbResult
  19.     End If
  20.     Set objForm = Nothing
  21.   Next objForm
  22.  
  23.   'Apply color to controls
  24.   For Each cntrl In frmSetup.Controls
  25.    If TypeOf cntrl Is Frame Or TypeOf cntrl Is OptionButton Or TypeOf cntrl Is CommandButton Then
  26.     cntrl.BackColor = uCol.rgbResult
  27.     End If
  28.     Set cntrl = Nothing
  29.   Next cntrl
  30.    For Each cntrl In frmMain.Controls
  31.    If TypeOf cntrl Is Frame Or TypeOf cntrl Is OptionButton Or TypeOf cntrl Is CommandButton Or TypeOf cntrl Is Label Then
  32.     cntrl.BackColor = uCol.rgbResult
  33.     End If
  34.     Set cntrl = Nothing
  35.   Next cntrl
  36. End Sub

My question is that if the above is situated in a module how do I tell it to apply the operation to the form without specifying the form name basically generics?

Thanks,


Nightwalker

Viewing all articles
Browse latest Browse all 21096

Trending Articles