
表格中要求看不到任何線條,但是又不能影響對列的動態屬性設定
uj5u.com熱心網友回復:
大概這樣procedure TForm1.cxGrid1BandedTableView1CustomDrawColumnHeader(
Sender: TcxGridTableView; ACanvas: TcxCanvas;
AViewInfo: TcxGridColumnHeaderViewInfo; var ADone: Boolean);
begin
DrawBandHeader(Sender, ACanvas, AViewInfo, ADone);
end;
procedure TForm1.DrawBandHeader(Sender: TObject; ACanvas: TcxCanvas;
AViewInfo: TcxCustomGridViewCellViewInfo; var ADone: Boolean);
const
MultiLines : array[Boolean] of Integer = (cxSingleLine, cxWordBreak);
ShowEndEllipsises : array[Boolean] of Integer = (0, cxShowEndEllipsis);
var
ATextRect, ABounds: TRect;
AFontTextColor, ABkColor: TColor;
ABorders : TcxBorders;
AText : string;
AFont : TFont;
isBand : Boolean;
begin
ABkColor := 0;
ABounds := AViewInfo.Bounds;
ABorders := [bTop, bBottom, bLeft, bRight];
AFont := ACanvas.Font;
ATextRect := AViewInfo.ContentBounds;
AFontTextColor := ACanvas.Font.Color;
InflateRect(ATextRect, -1, -1);
isBand := False;
if AViewInfo.ClassName = 'TcxGridBandHeaderViewInfo' then
isBand := True;
//設定顏色及滑鼠移上、按下效果
case AViewInfo.ButtonState of
cxbsDefault, cxbsNormal, cxbsDisabled:
ABkColor := clwhite;
cxbsHot:
ABkColor := $00FAE4DC;
cxbsPressed:
ABkColor := $908782;
end;
if not isBand then
begin
AText := TcxGridColumnHeaderViewInfo(AViewInfo).Column.Caption //列標題
end
else
AText := TcxGridBandHeaderViewInfo(AViewInfo).Band.Caption;
with ACanvas do
begin
//填充標題顏色
if (ABkColor <> clNone) then
begin
SetBrushColor(ABkColor);
FillRect(ABounds);
end;
//
if AText <> '' then
begin
Brush.Style := bsClear;
Font := AFont;
Font.Color := AFontTextColor;
DrawText(AText, ATextRect, cxAlignmentsHorz[taCenter] or cxAlignmentsVert[vaCenter] or MultiLines[False] or ShowEndEllipsises[False]);
Brush.Style := bsSolid;
end;
end;
with ABounds do
begin
// 這里是加邊框
ACanvas.Brush.Color := $908782;
if (not isBand) and (TcxGridColumnHeaderViewInfo(AViewInfo).Index = 0) then
if bLeft in ABorders then // 左邊框
ACanvas.FillRect(Rect(Left, Top, Left, Bottom));
if isBand then
begin
if bTop in ABorders then //上邊框
ACanvas.FillRect(Rect(Left, Top, Right, Top));
if bRight in ABorders then //右邊框
ACanvas.FillRect(Rect(Right, Top, Right, Bottom));
if bBottom in ABorders then //下邊框
ACanvas.FillRect(Rect(Left, Bottom, Right, Bottom));
end;
end;
ADone := True;
end;
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/20767.html
標籤:VCL組件開發及應用
上一篇:C++ 未命名名稱空間
下一篇:資料結構—鏈表
