May 10, 2024, 05:39:12 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Checkbox Color

Started by Bruce Peaslee, September 24, 2010, 04:36:45 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Bruce Peaslee

Hi,

How do I change the color of a checkbox control in a dialog?

As the user tabs through the dialog, I want the color to change as the control gets the focus, then back as it moves on.

Thanks,

Bruce
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

billhsln

This is how my program does it:

UINT BLACK, RED, GREEN, BLUE, YELLOW, CYAN, PINK, GREY, MAGENTA
UINT LBLUE, LYELLOW, WHITE, PURPLE, GOLD, SILVER, BROWN

GOLD    = RGB(255,215,0)
YELLOW  = RGB(255,255,0)
LYELLOW = RGB(255,255,125)
GREEN   = RGB(0,255,0)
BLUE    = RGB(0,0,255)
RED     = RGB(255,0,0)
CYAN    = RGB(0,255,255)
PINK    = RGB(255,192,203)
GREY    = RGB(125,125,125)
LBLUE   = RGB(0,125,255)
MAGENTA = RGB(255,0,255)
PURPLE  = RGB(128,0,128)
BROWN   = RGB(165,42,42)
SILVER  = RGB(105,105,105)
WHITE   = RGB(255,255,255)
BLACK   = RGB(0,0,0)

' Set color of Check Boxes
SETCONTROLCOLOR d1,D1_CB1, PINK, PURPLE
SETCONTROLCOLOR d1,D1_CB2, CYAN, BLUE

Hope that helps.

Bill
When all else fails, get a bigger hammer.

LarryMc

If you are just wanting to change the fore/background colors of the overall area the box and text occupy then what Bill said with the SETCONTROLCOLOR command is correct.

If you are wanting to change the color of the little box itself I think you will have to subclass it and do your on WM_PAINT handler.
Or create custom "button" with the BS_OWNERDRAWN flag and draw everything yourself in the custom buttons handler.

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Bruce Peaslee

I just wanted to change the color as the user tabs through them.

I checked Bill's example and it works. However, the checkboxes weren't sending the  @BN_SETFOCUS and @BN_KILLFOCUS messages until I added BS_NOTIFY style to the control.


Case  LOT_CHK_VACANT
Case& LOT_CHK_FORSALE
Case& LOT_CHK_RENTED
    If @NOTIFYCODE = BN_SETFOCUS
        SetControlColor dlgLotData, @CONTROLID, BLACK, RED
    EndIf
    If @NOTIFYCODE = BN_KILLFOCUS
        SetControlColor dlgLotData, @CONTROLID, BLACK, RGB(175, 175, 175)
    EndIf
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

LarryMc

I've been bit by forgrtting the BS_NOTIFY flag before.

Just my personal preference:

Case  LOT_CHK_VACANT
Case& LOT_CHK_FORSALE
Case& LOT_CHK_RENTED
    SELECT @NOTIFYCODE
       case BN_SETFOCUS
          SetControlColor dlgLotData, @CONTROLID, BLACK, RED
       case  BN_KILLFOCUS
          SetControlColor dlgLotData, @CONTROLID, BLACK, RGB(175, 175, 175)
   ENDSELECT


LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Bruce Peaslee

Yeah, they call them "bytes" for a reason.

Thanks to both of you.
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles