![]() |
Stringgrid Menuleiste nicht zentriert
Ich habe eine Demo von hier verwendet und wollte die Menunamen in meinem Stringgrid (Row 0) zentrieren, sie bleiben aber linksbündig, was mache ich falsch?
Delphi-Quellcode:
procedure Tlote.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState); var celltext: string; begin with (Sender as TStringGrid) do begin celltext := Cells[ACol, ARow]; if (ARow = 0) then // Nur für Zeile 0 begin canvas.Font.Style := canvas.Font.Style + [fsBold]; canvas.Brush.Color := clteal; // Hintergrundfarbe canvas.Font.Color := clwhite; // Schriftfarbe DrawText(Canvas.Handle, PChar(celltext), Length(celltext), Rect, DT_Center) // Schrift zentrieren end; if (ACol = 1) and (ARow > 0) then begin canvas.Brush.Color := clmoneygreen; canvas.Font.Style := canvas.Font.Style + [fsBold]; canvas.Font.Color := clblue; // Schriftfarbe end; if (ACol = 0) and (ARow > 0) then begin canvas.Font.Size := 12; canvas.Font.Style := canvas.Font.Style + [fsBold]; canvas.Font.Color := clred; // Schriftfarbe end; // Hier beginnt nun das Zeichnen: Canvas.FillRect(Rect); // Hintergrund zeichnen DrawText(Canvas.Handle, PChar(celltext), Length(celltext), Rect, DT_SINGLELINE); // Textausgeben // Optional kann der Text auch Zentriert werden. // dann mit diesem Parameter; // DT_SINGLELINE or DT_Center or DT_VCENTER end; end; |
Re: Stringgrid Menuleiste nicht zentriert
Hai tom_po,
hihi der Code kommt mir doch bekannt vor. ;-) Du gibst in Zeile 14 den Text zwar zentiert aus aber dann löschst Du ihn in Zeile 32 wieder um in dann wieder linksbündig zu zeichenen. Am besten nimmst Du eine Variable in der Du den "Ausgabemodus" speicherst und dann ganz am Ende verwendest.
Delphi-Quellcode:
procedure Tlote.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState); var celltext: string; Mode : Cardinal; begin Mode := DT_SINGLELINE; with (Sender as TStringGrid) do begin celltext := Cells[ACol, ARow]; if (ARow = 0) then // Nur für Zeile 0 begin Mode := Mode or DT_Center; end; // Hier beginnt nun das Zeichnen: Canvas.FillRect(Rect); // Hintergrund zeichnen DrawText(Canvas.Handle, PChar(celltext), Length(celltext), Rect, Mode); // Textausgeben end; end; |
Re: Stringgrid Menuleiste nicht zentriert
genau das wollte ich, vielen, vielen Dank.
sorry, dass ich deinen Namen oben nicht erwähnt hatte |
Alle Zeitangaben in WEZ +1. Es ist jetzt 10:21 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz