Einzelnen Beitrag anzeigen

madtom

Registriert seit: 24. Feb 2005
Ort: Hamburg
115 Beiträge
 
Delphi XE7 Professional
 
#8

AW: StringGrid Inhalte zentrieren.

  Alt 27. Jun 2011, 22:46
Hier noch ein Beispiel dazu von Peter Below (TeamB)

Delphi-Quellcode:
procedure TForm1.StringGrid1DrawCell(Sender: TObject; nCol, nRow: Longint; nRect: TRect;
  State: TGridDrawState);
var
  Cpos: Integer;
begin
  with (Sender as TStringGrid) do
    with Canvas do
    begin
      Font := (Sender as TStringGrid).Font;

      if (gdSelected in State) and (Sender = ActiveControl) then
      begin
        Brush.Color := clHighlight;
        Font.Color := clHighlightText;
      end
      else if (gdFixed in State) then
        Brush.Color := (Sender as TStringGrid).FixedColor
      else
        Brush.Color := (Sender as TStringGrid).Color;
      FillRect(nRect);
      SetBkMode(Handle, TRANSPARENT);

      if (nRow = 0) or (nCol = 2) then
      { Centered Text }
      begin
        SetTextAlign(Handle, TA_CENTER);
        with nRect do
          Cpos := Left + ((Right - Left) div 2) - 1;
        TextOut(Cpos, nRect.Top + 2, Cells[nCol, nRow]);
      end
      else if (nCol = 3) or (nCol = 4) then
      { Right Justified Text }
      begin
        SetTextAlign(Handle, TA_Right);
        TextOut(nRect.Right - 2, nRect.Top + 2, Cells[nCol, nRow]);
      end
      else
      begin
        { normal Left Justified Text }
        SetTextAlign(Handle, TA_LEFT);
        TextOut(nRect.Left + 2, nRect.Top + 2, Cells[nCol, nRow]);
      end;
    end;
end;
Gruß madtom
Thomas
Delphi Programming
  Mit Zitat antworten Zitat