1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33:
| procedure StringGridAlignment(Grid: TStringGrid; Rect: TRect; ACol, ARow: Integer; Alignment: TAlignment; LineBreak: Boolean); var TextOut: String; begin Grid.Canvas.FillRect(Rect); TextOut := Grid.Cells[ACol,ARow]; if LineBreak = false then begin if Alignment = taLeftJustify then DrawText(Grid.Canvas.Handle, PChar(TextOut), StrLen(PChar(TextOut)), Rect,DT_LEFT); if Alignment = taCenter then DrawText(Grid.Canvas.Handle, PChar(TextOut), StrLen(PChar(TextOut)), Rect,DT_CENTER); if Alignment = taRightJustify then DrawText(Grid.Canvas.Handle, PChar(TextOut), StrLen(PChar(TextOut)), Rect,DT_RIGHT); end else begin if Alignment = taLeftJustify then DrawText(Grid.Canvas.Handle, PChar(TextOut), StrLen(PChar(TextOut)), Rect,DT_LEFT+DT_WORDBREAK); if Alignment = taCenter then DrawText(Grid.Canvas.Handle, PChar(TextOut), StrLen(PChar(TextOut)), Rect, DT_CENTER+DT_WORDBREAK); if Alignment = taRightJustify then DrawText(Grid.Canvas.Handle, PChar(TextOut), StrLen(PChar(TextOut)), Rect, DT_RIGHT+DT_WORDBREAK); end; end;
procedure TForm1.SG1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); begin StringGridAlignment(SG1, Rect, ACol, ARow, taRightJustify, True); end; |