开发者

problem with a code for string grid ( align center )

Delphi: How to make cells' texts in TStringGri开发者_JAVA百科d center aligned?

When I use the top code (OnDraw part), it doesn't delete the first text and write the new text on the old text and one sel will duplicate .


You need to add a call to TCanvas.FillRect before writing out the new text:

procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
var
  S: String;
begin
  S := StringGrid1.Cells[ACol, ARow];
  StringGrid1.Canvas.FillRect(Rect);
  SetTextAlign(StringGrid1.Canvas.Handle, TA_CENTER);
  StringGrid1.Canvas.TextRect(Rect,
    Rect.Left + (Rect.Right - Rect.Left) div 2, Rect.Top + 2, S);
end;

Note you'll also have to make sure that the TStringGrid.DefaultDrawing is set to False in order for this to work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜