I'm using the following code to show a checkbox inside a DBGrid. It works (at least was expected to) both themed and non-themed VCL style:
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
const
CtrlState: Array[Boolean] of Integer = (DFCS_BUTTONCHECK, DFCS_BUTTONCHECK or DFCS_CHECKED);
CtrlStateXP: Array[Boolean] of TThemedButton = (tbCheckBoxUncheckedNormal, tbCheckBoxCheckedNormal);
var
CheckBoxRectangle : TRect;
Details: TThemedElementDetails;
begin
if Column.Field.DataType = ftBoolean then
begin
Column.Title.Alignment := taCenter;
Column.Alignment := taCenter;
TDBGrid(Sender).Canvas.FillRect(Rect);
if ThemeServices.ThemesEnabled then
begin
Details := ThemeServices.GetElementDetails(CtrlStateXP[Column.Field.AsBoolean]);
ThemeServices.DrawElement(TDBGrid(Sender).Canvas.Handle, Details, Rect);
end
else
begin
CheckBoxRectangle.Left := Rect.Left + 2;
CheckBoxRectangle.Right := Rect.Right - 2;
CheckBoxRectangle.Top := Rect.Top + 2;
CheckBoxRectangle.Bottom := Rect.Bottom - 2;
DrawFrameControl(TDBGrid(Sender).Canvas.Handle, CheckBoxRectangle, DFC_BUTTON, CtrlState[Column.Field.AsBoolean]);
end;
end;
end;
It's working fine, except when I move over the rows, the style becomes 'strange', like bellow:
Any help? Thanks.
Aucun commentaire:
Enregistrer un commentaire