0
votes

I have a dbcheckbox component I need to change its background colors to express the checked or not checked status. I need that updated when user navigate between records using dbnavigator component.

The dataset is on data module and I dont want to use its events anyway so please advise should I override the component and how ?

Thanks

2

2 Answers

1
votes

With enabled Runtimethemes, changing of color is not possible, perhaps changing of FontStyle might fit your needs too.
If not you would be able to call an own Notifyevent at the part of code with
"Message.Msg =BM_SETCHECK" to react in another way, e.g. changing the color of an underlying shape.

  TDBCheckBox=Class(DBCtrls.TDBCheckbox)
        procedure WndProc(var Message: TMessage); override;
  private
  End;

  TForm1 = class(TForm)
    DBCheckBox1: TDBCheckBox;
    procedure FormCreate(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation
{$R *.dfm}

{ TDBCheckBox }



procedure TDBCheckBox.WndProc(var Message: TMessage);
var
 fs:TFontStyles;
begin
  inherited;
   if Message.Msg =BM_SETCHECK then
         begin
         if checked then    Font.Color := clLime else Font.Color := clRed;  // Will only work if runtimethemes are disabled
         fs := Font.Style;
         if checked then  Include(fs, fsbold)  else Exclude(fs, fsbold);
         Font.Style := fs;
         end;
end;
0
votes

You can use the OnClick-Event of the DBCheckBox, this is fired every time the Checked-property changes. Unfortuately, you can not use a background-color of the dbcheckbox, because in themed windows, the property "color" has no effect. You can place a TPanel behind the dbCheckbox instead and use the Color of the Panel. Or you can change the Font.Color instead. So the event OnClick looks like that:

procedure TForm1.DBCheckBox1Click(Sender: TObject);
begin
  if DBCheckBox1.Checked then
    DBCheckBox1.Font.Color := clRed
  else
    DBCheckBox1.Font.Color := clWindowText;
end;