好像无法控制StringGrid中一个Cell的对齐方式(20分)

K

kaneboy

Unregistered / Unconfirmed
GUEST, unregistred user!
如果我希望改变一个StringGrid中某个Cell的对齐方式(比如改为右对齐),好像没有任何
办法啊...郁闷
 
假设第2,4列右对齐,其他的左对齐
procedure TForm1.StringGrid1DrawCell(Sender: TObject;
ACol, ARow: Integer;
Rect: TRect;
State: TGridDrawState);
var
Area: TRect;
begin
with StringGrid1, StringGrid1.Canvas do
begin
FillRect(Rect);
Area:= Rect;
InflateRect(Area, -2, -2);
if (ACol=1) or (ACol=3) then
DrawText(Handle, PChar(Cells[ACol, ARow]),
Length(Cells[ACol, ARow]), Area, DT_RIGHT)
else
TextRect(Rect, Rect.Left + 2, Rect.Top + 2, Cells[ACol, ARow]);
end;
end;
 
接受答案了.
 
顶部