Delphi 10.1 Berlin下TStringGrid单元格样式设定
2016-07-13 13:43
525 查看
设定TStringGrid的DefaultDraw = true,系统自动给表格绘制默认的样式和效果。设定自定义格式前,先填充单元格的背景色,以清除原内容。
procedure TShowDetailForm.GridForwardDrawCell( Sender : TObject; ACol, ARow : Integer; Rect : TRect; State : TGridDrawState ); const FixSpace = 3; var cellText : string; i, j, tX, tY : Integer; txtWidth, txtHeight : Integer; // interleavingColor : TColor; begin // interleavingColor := TStringGrid(Sender).FixedColor; // with TStringGrid( Sender ) do begin cellText := Cells[ ACol, ARow ].Trim; txtWidth := Canvas.TextWidth( cellText ); txtHeight := Canvas.TextHeight( cellText ); // if ACol = 0 then begin // 第一列 // 设定样式 背景色 字体色 Canvas.Brush.Color := TStyleManager.ActiveStyle.GetStyleColor( scCategoryButtons ); Canvas.FillRect( Rect ); if ARow <> 0 then begin // 水平居左 垂直居中 tX := Rect.Left + FixSpace; tY := Rect.Top + ( Rect.Height - txtHeight ) div 2; Canvas.Font.Style := [ fsBold ]; Canvas.TextRect( Rect, tX, tY, cellText ); end else begin // 水平居中 垂直居中 tX := Rect.Left + ( Rect.Width - txtWidth ) div 2; tY := Rect.Top + ( Rect.Height - txtHeight ) div 2; Canvas.FillRect( Rect ); Canvas.Font.Style := [ fsBold ]; Canvas.TextRect( Rect, tX, tY, cellText ); end; end else begin // 第一行 if ARow = 0 then begin // 水平居中 垂直居中 tX := Rect.Left + ( Rect.Width - txtWidth ) div 2; tY := Rect.Top + ( Rect.Height - txtHeight ) div 2; // 填充背景色,清除原内容 Canvas.Brush.Color := TStyleManager.ActiveStyle.GetStyleColor( scCategoryButtons ); Canvas.FillRect( Rect ); Canvas.Font.Style := [ fsBold ]; Canvas.TextRect( Rect, tX, tY, cellText ); end else // 内容区 begin // 水平居右 垂直居中 if ACol mod 4 = 0 then begin tX := Rect.Left + ( Rect.Width - txtWidth - FixSpace ) div 2; tY := Rect.Top + ( Rect.Height - txtHeight ) div 2; Canvas.Font.Style := [ fsBold ]; if Cells[ ACol, ARow ] = CorrectChar then Canvas.Font.Color := clGreen else Canvas.Font.Color := clRed; end else begin tX := Rect.Left + ( Rect.Width - txtWidth - FixSpace ); tY := Rect.Top + ( Rect.Height - txtHeight ) div 2; Canvas.Font.Style := [ ]; // Canvas.Font.Color := TStyleManager.ActiveStyle.GetStyleFontColor(sfButtonTextNormal) ; end; /// if ( State * [ gdSelected, gdRowSelected ] ) <> [ ] then Canvas.Brush.Color := TStyleManager.ActiveStyle.GetStyleColor( scButtonFocused ) else begin if ( ACol <= 4 ) or ( ( ACol >= 9 ) and ( ACol <= 12 ) ) then Canvas.Brush.Color := FixedColor // clWebYellowGreen else Canvas.Brush.Color := TStyleManager.ActiveStyle.GetStyleColor( scGrid ); end; //无数据时,居中 if Cells[ACol,ARow].Trim = '-' then begin tX := Rect.Left + ( Rect.Width - txtWidth - FixSpace ) div 2; tY := Rect.Top + ( Rect.Height - txtHeight ) div 2; end; // 填充单元格背景色 Canvas.FillRect( CellRect( ACol, ARow ) ); Canvas.TextRect( Rect, tX, tY, cellText ); end; end; end; end;
相关文章推荐
- c#中的webservice调用delphi写的dll函数的方法
- DelphiXE_画图
- delphi中使用mediaplayer控件播放音乐
- delphi报警声音 Beep、MessageBeep 和 Windows.Beep
- Delphi 使用双缓冲解决图片切换时的闪烁问题 good
- Delphi TCOM控件串口通信调试寻找文件传输速度慢的原因
- delphi for xx in xx do 语法的使用示例
- Delphi XE7的安卓程序如何调用JAVA的JAR,使用JAVA的类?
- delphi连接mysql
- delphi 编译的时候 把Warning去除的方法
- delphiXE Implicit string cast from 'AnsiString' to 'string'
- Delphi通过GetFileVersionInfo和VerQueryValue等API函数取得详细EXE信息
- DELPHI获取网卡MAC地址
- StrPCopy与StrPas功能正好相反,作用是与C语言字符串和Delphi的String相互转化
- delphi文件解析
- SQL语句在Delphi中的使用规则
- 程序的开机关机重启,开机启动,休眠功能delphi实现
- delphi中最小化其他程序及所有程序最小化
- 手动升级Delphi控件时,修改inc文件的办法
- 反调试技术(Delphi版)