TStringGrid中单元格显示文字的排列问题(20分)

  • 主题发起人 主题发起人 muyixin
  • 开始时间 开始时间
M

muyixin

Unregistered / Unconfirmed
GUEST, unregistred user!
我找了好久都不知道怎么设置 delphi自带的表格 中文字的排列属性
我想让 单元格中的文字 在单元格的 垂值 水平方向 都居中 改怎么设置呢?
 
procedure TForm4.ImpStringGrid1DrawCell(Sender: TObject; ACol,
ARow: Integer; Rect: TRect; State: TGridDrawState);
const
WSpace = 2;
HSpace = 2;
var
tmpstr: string;
w,h: integer;
iType:Integer;
Area:TRect;
begin
iType:=1;
if iType=0 then begin
tmpstr := (Sender as TStringGrid).Cells[ACol,ARow];
with (Sender as TStringGrid).Canvas do begin
w := TextWidth(tmpstr);
h := TextHeight(tmpstr);
if (gdFixed in State) then
TextRect(Rect,trunc((Rect.Right+Rect.Left-w)/2)+WSpace, //居中显示
trunc((Rect.Bottom+Rect.Top-H)/2)+HSpace,tmpstr)
else //右对齐显示
TextRect(Rect,Rect.Right-WSpace-W,Rect.Bottom-HSpace-H,tmpstr);
end;
end else begin
//画文本,可以设置显示的对齐方式
with (Sender as TStringGrid).Canvas do begin
FillRect(Rect);
Area:= Rect;
InflateRect(Area, -2, -2);
//if ARow=0 then
DrawText(Handle, PChar((Sender as TStringGrid).Cells[ACol, ARow]),Length((Sender as TStringGrid).Cells[ACol, ARow]), Area,DT_CENTER + DT_SINGLELINE + DT_VCENTER);//居中
//DrawText(Handle, PChar((Sender as TStringGrid).Cells[ACol, ARow]),Length((Sender as TStringGrid).Cells[ACol, ARow]), Area, DT_CENTER or DT_VCENTER);//居中
//else if (ACol=0) and (ARow<>0) then
//DrawText(Handle, PChar(Cells[ACol, ARow]),Length(Cells[ACol, ARow]), Area, DT_RIGHT)//左对齐
//else
//DrawText(Handle, PChar(Cells[ACol, ARow]),Length(Cells[ACol, ARow]), Area, DT_LEFT);//右对齐
end;
end;
end;
 
啊 这是要自己编程实现么 StringGrid没有自带的属性可以设置么?
 
StringGrid没有自带的属性,如果自己编程嫌麻烦可以用三方控件。
 
接受答案了.
 

Similar threads

D
回复
0
查看
960
DelphiTeacher的专栏
D
D
回复
0
查看
893
DelphiTeacher的专栏
D
D
回复
0
查看
973
DelphiTeacher的专栏
D
后退
顶部