if (ARow>0) and (ACol<3) then //设置左对齐 begin SetTextAlign(StringGridDisplay.Canvas.Handle,TA_Left); StringGridDisplay.Canvas.FillRect(Rect); StringGridDisplay.Canvas.TextRect(Rect,Rect.Left+5,rect.Top+5,StringGridDisPlay.Cells[acol,arow]); end else if (ARow>0) and (ACol>3) then //设置右对齐 begin SetTextAlign(StringGridDisplay.Canvas.Handle,TA_Right); StringGridDisplay.Canvas.FillRect(Rect); StringGridDisplay.Canvas.TextRect(Rect,Rect.Right-2,Rect.Top+5,StringGridDisPlay.Cells[acol,arow]); end; 自己去改改,行的.
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); var S: String; begin StringGrid1.Canvas.FillRect(Rect); S := StringGrid1.Cells[ACol,ARow]; DrawText(StringGrid1.Canvas.Handle, PChar(S), Length(S), Rect, DT_CENTER);end;
to borlandor(大民) 这样好象是只是在那个cell中横向对齐,我要的是在那个cell的中间(横向和纵向),如何做?
设置Alignment为TaCenter
begin
SetTextAlign(StringGridDisplay.Canvas.Handle,TA_Left);
StringGridDisplay.Canvas.FillRect(Rect);
StringGridDisplay.Canvas.TextRect(Rect,Rect.Left+5,rect.Top+5,StringGridDisPlay.Cells[acol,arow]);
end else
if (ARow>0) and (ACol>3) then //设置右对齐
begin
SetTextAlign(StringGridDisplay.Canvas.Handle,TA_Right);
StringGridDisplay.Canvas.FillRect(Rect);
StringGridDisplay.Canvas.TextRect(Rect,Rect.Right-2,Rect.Top+5,StringGridDisPlay.Cells[acol,arow]);
end;
自己去改改,行的.
Rect: TRect; State: TGridDrawState);
var S: String;
begin
StringGrid1.Canvas.FillRect(Rect);
S := StringGrid1.Cells[ACol,ARow];
DrawText(StringGrid1.Canvas.Handle, PChar(S), Length(S), Rect, DT_CENTER);end;
这样好象是只是在那个cell中横向对齐,我要的是在那个cell的中间(横向和纵向),如何做?
可以参见
http://www.csdn.net/Develop/read_article.asp?id=8396
中的WriteText.