Autor Beitrag
mhsteuer
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 23



BeitragVerfasst: Fr 26.11.04 13:44 
Hallo Leute!

Wie kann man den Text in einer StringGrid-Zelle zentrieren?

Danke!


Moderiert von user profile iconTino: Topic aus Sonstiges verschoben am So 28.11.2004 um 22:10

_________________
Mittsommernacht
.Chef
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1112



BeitragVerfasst: Fr 26.11.04 14:19 
Du setzt den Style auf OwnerDraw, und nutzt dann das OnDrawCell-Ereignis, um den Text manuell zu zentrieren:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
var
  a : Integer;
begin
  with (Sender as TStringGrid) do
  begin
    a:=(Rect.Right-Rect.Left-Canvas.TextWidth(Cells[ACol,ARow])) div 2;
    Canvas.TextRect(Rect,Rect.Left+a,Rect.Top+2,Cells[ACol,ARow]);
    Canvas.FrameRect(Rect);
  end;
end;

Ungetestet. Aber so in etwa ...

Gruß,
Jörg

_________________
Die Antworten auf die 5 häufigsten Fragen:
1. Copy(), Pos(), Length() --- 2. DoubleBuffered:=True; --- 3. Application.ProcessMessages bzw. TThread --- 4. ShellExecute() --- 5. Keine Vergleiche von Real-Typen mit "="!