☆DBGridのColumn描画
ランタイムテーマを有効にしても、頑なに自分のスタイルを守るコンポーネントがあります。
DBGridもその中の一つで、スクロールバーやPickListのボタンは、いい感じなのにIndicatorやColumnは
このように最悪です。
そこで、Column部分を描画してみます。 Indicator部分は面倒なので、表示させないようにしています。 Indicatorも描画したいという方は、TCustomDBGrid.DrawCellを参考にして下さい。
宣言部です。
実装部です。
こんな風になりました(^^;
そこで、Column部分を描画してみます。 Indicator部分は面倒なので、表示させないようにしています。 Indicatorも描画したいという方は、TCustomDBGrid.DrawCellを参考にして下さい。
宣言部です。
TMyDBGrid = class(TDBGrid) protected procedure DrawCell(ACol, ARow: Longint; ARect: TRect; AState: TGridDrawState); override; public constructor Create(AOwner: TComponent); override; end;
実装部です。
uses GraphUtil; constructor TMyDBGrid.Create(AOwner: TComponent); begin inherited Create(AOwner); Options := Options - [dgIndicator]; end; procedure TMyDBGrid.DrawCell(ACol, ARow: Integer; ARect: TRect; AState: TGridDrawState); const AlignFlags : array [TAlignment] of Integer = (DT_LEFT, DT_RIGHT, DT_CENTER); var Text: String; Flags: LongInt; begin inherited DrawCell(ACol,ARow,ARect,AState); if (ARow = 0) and (Columns.Count > ACol) then begin // 背景の描画 SetBkMode(Canvas.Handle, TRANSPARENT); InflateRect(ARect, +1, +1); GradientFillCanvas(Canvas, clWhite, clGradientInactiveCaption, ARect, gdVertical); // カラム間の線 Canvas.Pen.Color := clSilver; Canvas.MoveTo(ARect.Left +0, ARect.Top +1); Canvas.LineTo(ARect.Left +0, ARect.Bottom -1); // タイトルの描画 Canvas.Font.Assign(TitleFont); Text := Columns[ACol].Title.Caption; Flags := DT_SINGLELINE or DT_VCENTER or AlignFlags[Columns[ACol].Title.Alignment]; InflateRect(ARect, -2, -2); DrawText(Canvas.Handle, PChar(Text), Length(Text), ARect, Flags); end; end;
こんな風になりました(^^;
| 固定リンク