实现TStringGrid的左对齐、居中和右对齐
2012-05-12 11:02
155 查看
//sgrdQty: TStringGrid
procedure TfrmPDStock.sgrdQtyDrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var
sText: String;
iTextWidth: Integer;
rNum: Double;
begin
inherited;
with sgrdQty do
begin
sText := Cells[ACol, ARow]; //輸出內容
iTextWidth := canvas.TextWidth(sText); //輸出內容寬度
//
if ARow = 0 then
Canvas.TextRect(Rect, (Rect.left+Rect.right-iTextWidth) div 2, Rect.Top+2, sText) //第1行, 居中
else if ACol = 0 then
Canvas.TextRect(Rect, Rect.Left+2, Rect.top+2, sText) //第1列, 左對齊
else
begin
//如果<0以紅色顯示
if TryStrToFloat(sText, rNum) and (rNum < 0) then
Canvas.Font.Color := clRed
else
Canvas.Font.Color := clWindowText;
//
Canvas.TextRect(Rect, Rect.right - iTextWidth - 2 ,Rect.Top + 2, sText); //其它, 右對齊心
end;
end;
end;
procedure TfrmPDStock.sgrdQtyDrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var
sText: String;
iTextWidth: Integer;
rNum: Double;
begin
inherited;
with sgrdQty do
begin
sText := Cells[ACol, ARow]; //輸出內容
iTextWidth := canvas.TextWidth(sText); //輸出內容寬度
//
if ARow = 0 then
Canvas.TextRect(Rect, (Rect.left+Rect.right-iTextWidth) div 2, Rect.Top+2, sText) //第1行, 居中
else if ACol = 0 then
Canvas.TextRect(Rect, Rect.Left+2, Rect.top+2, sText) //第1列, 左對齊
else
begin
//如果<0以紅色顯示
if TryStrToFloat(sText, rNum) and (rNum < 0) then
Canvas.Font.Color := clRed
else
Canvas.Font.Color := clWindowText;
//
Canvas.TextRect(Rect, Rect.right - iTextWidth - 2 ,Rect.Top + 2, sText); //其它, 右對齊心
end;
end;
end;
相关文章推荐
- css实现一行文字居中,多行文字左对齐
- 实现字符串的对齐(左对齐、右对齐、居中)
- 纯CSS实现文字一行居中,多行左对齐的方法
- Qt学习笔记之文本编辑器实现加粗、倾斜、下划线、字体、居中对齐、左对齐、右对齐
- C语言实现比特位数组在目标空间左右居中对齐三种方式
- 实现表格内容第一行居中,其他行与第一行左对齐
- html使用display:inline-block实现标签右对齐,值左对齐效果。和设置div宽度,并居中显示。嵌套div的里层div文字居中显示
- Android学习——LinearLayout布局实现居中、左对齐、右对齐
- [office]学术论文中的公式居中,编号右对齐的实现
- 论文中如何实现公式居中并且编号右对齐
- 利用vertical-align:middle实现行内元素的水平垂直居中对齐
- Word2007在论文中如何同时实现公式居中、编号右对齐
- 纯CSS实现文字一行居中,多行左对齐的方法
- RecyclerView利用GridLayoutManager实现少于span数量时候居中对齐
- 实现 多行文本在父容器里 先居中 并且每行文本都左对齐
- iOS 8UIAlertcontroller如何实现 message左对齐 ,title居中显示
- 纯CSS实现文字一行居中,多行左对齐的方法
- Swift环境下实现UILabel居上 居中 居下对齐
- Swift环境下实现UILabel居上 居中 居下对齐
- Word2010利用公式编辑器实现公式“显示”“居中”公式编号右对齐