Delphi 10.1 Berlin下TStringGrid单元格样式设定
来源:互联网 发布:软件规模度量单位 编辑:程序博客网 时间:2024/04/20 13:50
设定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;
1 0
- Delphi 10.1 Berlin下TStringGrid单元格样式设定
- Delphi berlin 如何自定义Listview外观样式
- Delphi 10.1 Berlin Update1下载破解激活
- mydac 7.6.1.1 for delphi 10.1 berlin
- mydac 7.6.1.1 for delphi 10.1 berlin
- Rad Studio 10.1 Berlin,Delphi 10.1 Berlin,C++ Builder 10.1 Berlin 官方ISO下载(附激活)
- Rad Studio 10.1 Berlin,Delphi 10.1 Berlin,C++ Builder 10.1 Berlin 官方ISO下载(附激活)
- delphi中打印TStringGrid
- delphi TStringGrid add CheckBox
- TStringgrid 单元格文字居中代码
- RAD Studio, Delphi, C++Builder 10.1 Berlin第二季优惠活动
- RAD Studio, Delphi, C++Builder 10.1 Berlin 第四季优惠活动
- delphi 10.1 berlin 开发iOS程序偏好设置(Settings Bundle)
- Delphi FMX Grid列头样式设定
- Delphi TStringGrid 类(1)
- Delphi精简版Embarcadero.Delphi.10.1.Berlin.RTM.v24.0.22858.6822.Lite.v13.0
- Delphi精简版Embarcadero.Delphi.10.1.Berlin.Update2.v24.0.25048.9432.Lite.v13.2
- RAD Studio, Delphi and C++Builder 10.1 Berlin 新版本功能介绍 - 首场在线教学
- Struts2的数据标签获取不到Person的name属性解决方案
- Android如何区别真机和模拟器
- unsolve problems:状况分析
- Jmeter对基于websocket协议的压力测试
- tomcat去掉项目名称
- Delphi 10.1 Berlin下TStringGrid单元格样式设定
- mysql表名忽略大小写设置
- Java并发编程:Executor框架
- fgetc
- ImageView 宽度顶边显示,高度保持比例
- Android 6.0拨号界面响应工程码流程
- java布局——流式布局
- Oracle Instant Client(即时客户端) 安装与配置
- [JQ权威指南]使用全局函数get()向服务器请求数据