StringGrid 的某一列的数据向 右 对齐 RT3X 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在DrawCell事件中写:if ACol = x then DrawText(SG.Canvas.Handle,PChar(SG.Cells[ACol,ARow]),Length(SG.Cells[ACol,ARow]),Rect,DT_Right); procedure TFrmReturns.SgSaleDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);var sg: TStringGrid; //中间变量 CellText: String; //单元格的字符 aTextLeft, aTextTop: Integer; //字符串的左边距和上边距 aTextWidth, aTextHeight: Integer; //字符串的宽和高begin inherited; sg := (Sender as TStringGrid); CellText := sg.Cells[ACol, ARow]; sg.Canvas.Font := sg.Font; if (gdFixed in State) then // String Grid Cell 为固定 begin sg.Canvas.Brush.Color := sg.FixedColor; sg.Canvas.FillRect(Rect); Frame3D(sg.Canvas, Rect, clBtnHighlight, clBtnShadow, 1); end else begin // String Grid Cell 目前被选取 或 输入焦点 if (gdSelected in State) or (gdFocused in State) then begin sg.Canvas.Brush.Color := clHighlight; sg.Canvas.Font.Color := clHighlightText; end else // String Grid Cell 般状况 begin sg.Canvas.Brush.Color := sg.Color; sg.Canvas.Font.Color := sg.Font.Color; end; sg.Canvas.FillRect(Rect); end; aTextWidth := sg.Canvas.TextWidth(CellText); aTextHeight := sg.Canvas.TextHeight(CellText); aTextTop := Rect.Top + (Rect.Bottom - Rect.Top - aTextHeight) div 2; // 文字垂直置中 case ARow of 0:begin aTextLeft := Rect.Left + (Rect.Right - Rect.Left - aTextWidth) div 2; end; else case ACol of 1..2, 9: aTextLeft := Rect.Left + 2; // 文字置左 3..6: aTextLeft := Rect.Right - aTextWidth - 2; // 文字靠右 7..8: aTextLeft := Rect.Left + (Rect.Right - Rect.Left - aTextWidth) div 2; // 文字置中 else aTextLeft := Rect.Left + 2; end; end; sg.Canvas.TextRect(Rect, aTextLeft, aTextTop, CellText) ;end; procedure TfmgFundsDetail.RzGrdDataDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);var Area: TRect;begin with RzGrdData, RzGrdData.Canvas do begin //贷币右对齐 FillRect(Rect); Area:= Rect; InflateRect(Area, -2, -2); if (ACol=3)or (ACol=4) or (ACol=5) then DrawText(Handle, PChar(Cells[ACol, ARow]), Length(Cells[ACol, ARow]), Area, DT_RIGHT) else TextRect(Rect, Rect.Left + 4, Rect.Top + 2, Cells[ACol, ARow]); end;end; Excel单元格格式 求解!playsound函数问题 怎样合并多个二进制文件? 高手帮帮我,'喆'字不能显示问题? ★DBGrid的bug,请高手救命!★ 求助:关于stringgrid的问题 TStringField控件在哪里? 请各位数据库高手帮忙 200分 来者有分,大家看看,不是很复杂的 TCOMBOBOX的控件如何响应LIST消失的那一刻??? 求最简单的FUNCTION,将ABCDEF,倒过来变成FEDCBA的写法! 请问团队开发用VSS是怎么管理版本的????
if ACol = x then
DrawText(SG.Canvas.Handle,PChar(SG.Cells[ACol,ARow]),Length(SG.Cells[ACol,ARow]),Rect,DT_Right);
Rect: TRect; State: TGridDrawState);
var
sg: TStringGrid; //中间变量
CellText: String; //单元格的字符
aTextLeft, aTextTop: Integer; //字符串的左边距和上边距
aTextWidth, aTextHeight: Integer; //字符串的宽和高
begin
inherited;
sg := (Sender as TStringGrid);
CellText := sg.Cells[ACol, ARow];
sg.Canvas.Font := sg.Font;
if (gdFixed in State) then // String Grid Cell 为固定
begin
sg.Canvas.Brush.Color := sg.FixedColor;
sg.Canvas.FillRect(Rect);
Frame3D(sg.Canvas, Rect, clBtnHighlight, clBtnShadow, 1);
end
else
begin
// String Grid Cell 目前被选取 或 输入焦点
if (gdSelected in State) or (gdFocused in State) then
begin
sg.Canvas.Brush.Color := clHighlight;
sg.Canvas.Font.Color := clHighlightText;
end
else // String Grid Cell 般状况
begin
sg.Canvas.Brush.Color := sg.Color;
sg.Canvas.Font.Color := sg.Font.Color;
end;
sg.Canvas.FillRect(Rect);
end;
aTextWidth := sg.Canvas.TextWidth(CellText);
aTextHeight := sg.Canvas.TextHeight(CellText);
aTextTop := Rect.Top + (Rect.Bottom - Rect.Top - aTextHeight) div 2; // 文字垂直置中
case ARow of
0:begin
aTextLeft := Rect.Left + (Rect.Right - Rect.Left - aTextWidth) div 2;
end;
else
case ACol of
1..2, 9: aTextLeft := Rect.Left + 2; // 文字置左
3..6: aTextLeft := Rect.Right - aTextWidth - 2; // 文字靠右
7..8: aTextLeft := Rect.Left + (Rect.Right - Rect.Left - aTextWidth) div 2; // 文字置中
else
aTextLeft := Rect.Left + 2;
end;
end;
sg.Canvas.TextRect(Rect, aTextLeft, aTextTop, CellText) ;
end;
ARow: Integer; Rect: TRect; State: TGridDrawState);
var
Area: TRect;
begin
with RzGrdData, RzGrdData.Canvas do begin //贷币右对齐
FillRect(Rect);
Area:= Rect;
InflateRect(Area, -2, -2);
if (ACol=3)or (ACol=4) or (ACol=5) then DrawText(Handle, PChar(Cells[ACol, ARow]),
Length(Cells[ACol, ARow]), Area, DT_RIGHT)
else TextRect(Rect, Rect.Left + 4, Rect.Top + 2, Cells[ACol, ARow]);
end;
end;