TDBGrid具有焦点时使用的高亮颜色由clBtnFace系统颜色确定。可以使用GetSysColor Windows API函数和COLOR_BTNFACE参数检索此颜色。以下是如何使用它的示例:
uses
Windows;
const
COLOR_BTNFACE = 15; // The COLOR_BTNFACE system color index
procedure TForm1.MyDBGridDrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
var
HighlightColor: TColor;
begin
// Set the highlight color based on whether the grid has focus or not
if TDBGrid(Sender).Focused then
HighlightColor := clHighlight // Use the default highlight color when focused
else
HighlightColor := GetSysColor(COLOR_BTNFACE); // Use the system button face color otherwise
// Draw the cell highlight
if (gdSelected in State) then
begin
TDBGrid(Sender).Canvas.Brush.Color := HighlightColor;
TDBGrid(Sender).Canvas.FillRect(Rect);
end;
// Draw the cell contents
TDBGrid(Sender).DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;
1条答案
按热度按时间rdrgkggo1#
TDBGrid具有焦点时使用的高亮颜色由clBtnFace系统颜色确定。可以使用GetSysColor Windows API函数和COLOR_BTNFACE参数检索此颜色。以下是如何使用它的示例: