delphi – TA_CENTER不适用于居中对齐StringGrid
发布时间:2020-12-15 09:18:42 所属栏目:大数据 来源:网络整理
导读:我必须在StringGrid(它的单元格)中居中对齐文本,我使用你在这里看到的代码.我在这里找到了另一个答案,我编辑了一些东西. procedure TForm1.StringGrid1DrawCell(Sender: TObject; aCol,aRow: Integer; aRect: TRect; aState: TGridDrawState);var LStrCell:
我必须在StringGrid(它的单元格)中居中对齐文本,我使用你在这里看到的代码.我在这里找到了另一个答案,我编辑了一些东西.
procedure TForm1.StringGrid1DrawCell(Sender: TObject; aCol,aRow: Integer; aRect: TRect; aState: TGridDrawState); var LStrCell: string; LRect: TRect; qrt:double; begin LStrCell := StringGrid1.Cells[ACol,ARow]; StringGrid1.Canvas.FillRect(aRect); LRect := aRect; DrawText(StringGrid1.Canvas.Handle,PChar(LStrCell),Length(LStrCell),LRect,TA_CENTER); //other code end; 我正在使用Lazarus并且它给了我一个错误,因为它无法识别TA_CENTER.有解决方案吗 解决方法
由于您使用的是Lazarus,我不会依赖于特定于平台的Windows API函数,而是使用内置的canvas
TextRect 方法.在(未经测试的)代码中,它可能是:
procedure TForm1.StringGrid1DrawCell(Sender: TObject; aCol,aRow: Integer; aRect: TRect; aState: TGridDrawState); var CellText: string; TextStyle: TTextStyle; begin CellText := StringGrid1.Cells[ACol,ARow]; StringGrid1.Canvas.FillRect(ARect); TextStyle := StringGrid1.Canvas.TextStyle; TextStyle.Alignment := taCenter; StringGrid1.Canvas.TextRect(ARect,CellText,TextStyle); ... end; 无论如何,您已经使用了一个TA_CENTER常量,它由不同的Windows API函数使用,由 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |