Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing the backcolor of data controls 1

Status
Not open for further replies.

STPMB

Programmer
Sep 13, 2002
28
US
I am trying to use the change the background color of data controls like, data combo, flexgrid, datalists, etc in a procedure but they don't seem to work when the color is identifed like

ControlBackColor = vbWindowBackground

but it does work with code

ControlBackColor = vbRed

what is the login behind this or is there somehwere I can find out which controls can use the system colors and which require an actual color from the color palette?
 
The value of a color, be it foreground or background is a number ranging from 0 to hex
0xFFFFFF, representing the 255 (0 to FF) shades of red, green, and blue. Much easier to think in hex for this.
Code:
0x FF FF FF
    R  G  B
Any symbolic constant (vbWindowBackground, vbRed, and one of your definition) may be used in the assignment statement, provided the definition of that constant is known to that procedure at execution time. Or you can simply assign the action number
Control.BackColor = 16777215 (that's white by the way)

vbRed = 16711680

The logic behind vbWindowBackground not working in some cases is that the constant
vbWindowBackground has not been defined within the scope of those cases where it doesn't work. When it does work, then there a statement something like the following
Code:
Const vbWindowBackground = 16777215
defined in your code, or in a control and or reference that is available to the routine at execute time. Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
What method is used to identify the windows background color and convert it for use in a procedure like above?
 
The surest way to get the current system color settings is to use the GetSysColor API.
Code:
Private Declare Function GetSysColor Lib "user32" (ByVal nIndex As Long) As Long

Const COLOR_SCROLLBAR = 0
Const COLOR_BACKGROUND = 1
Const COLOR_ACTIVECAPTION = 2
Const COLOR_INACTIVECAPTION = 3
Const COLOR_MENU = 4
Const COLOR_WINDOW = 5
Const COLOR_WINDOWFRAME = 6
Const COLOR_MENUTEXT = 7
Const COLOR_WINDOWTEXT = 8
Const COLOR_CAPTIONTEXT = 9
Const COLOR_ACTIVEBORDER = 10
Const COLOR_INACTIVEBORDER = 11
Const COLOR_APPWORKSPACE = 12
Const COLOR_HIGHLIGHT = 13
Const COLOR_HIGHLIGHTTEXT = 14
Const COLOR_BTNFACE = 15
Const COLOR_BTNSHADOW = 16
Const COLOR_GRAYTEXT = 17
Const COLOR_BTNTEXT = 18
Const COLOR_INACTIVECAPTIONTEXT = 19
Const COLOR_BTNHIGHLIGHT = 20
Const COLOR_2NDACTIVECAPTION = 27
Const COLOR_2NDINACTIVECAPTION = 28
and then is some routine in the code
Code:
Private Sub GetTheColor()
   Dim SetCol as Long
   SetCol = GetSysColor(COLOR_BACKGROUND)
End Sub
I hope you find this example helpful. Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top