Autor Beitrag
Abu36
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 59



BeitragVerfasst: Mo 20.03.06 19:42 
hi,

folgende frage:
ist es möglich, das die zahlen in einem stringgrid nicht linksbündig und nach oben verschoben angezeigt werden, sondern in der mitte stehen???


Moderiert von user profile iconraziel: Topic aus Algorithmen, Optimierung und Assembler verschoben am Mo 20.03.2006 um 19:49
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Mo 20.03.06 22:39 
Hallo,

ja :?

das sollte weiterhelfen:
Suche in der Entwickler-Ecke STRINGGRID ONDRAWCELL
oder
Suche in der Entwickler-Ecke STRINGGRID DRAWTEXT

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
Abu36 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 59



BeitragVerfasst: Di 21.03.06 15:13 
hab das jetzt so aus probiert.

waagerecht steht der zelleninhalt zentriert, geht das auch horizontal??

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
 
procedure TForm2.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;


Moderiert von user profile iconraziel: Code- durch Delphi-Tags ersetzt
Miri
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 657


Delphi 3 Prof., Delphi 2005 PE
BeitragVerfasst: Di 21.03.06 15:18 
ist "waagerecht" und "horizontal" nicht so ziemlich das selbe? :gruebel:
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Di 21.03.06 15:23 
Gemeint war ja sicherlich vertikal, oder? Na ja, aber da musst du doch nur dasselbe mit Bottom, Top und TextHeight machen!
Also der Offset von oben wäre dann:
ausblenden Delphi-Quelltext
1:
b := (Rect.Bottom - Rect.Top - Canvas.TextHeight(Cells[ACol,ARow])) div 2;					
chrisw
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 439
Erhaltene Danke: 3

W2K
D7
BeitragVerfasst: Di 21.03.06 15:34 
Da gab's mal was bei den Schweizern

www.swissdelphicente.../showcode.php?id=422

_________________
Man sollte keine Dummheit zweimal begehen, die Auswahl ist schließlich groß genug.
Abu36 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 59



BeitragVerfasst: Di 21.03.06 15:45 
danke funktioniert, ich meinte vertikal
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Di 21.03.06 16:12 
Hallo,

da ich weiter oben DrawText erwähnt habe,
will ich die Variante hier auch mal nachreichen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
var  s : String;
begin
  with StringGrid1 do
    begin
    s := Cells[aCol,aRow];
    Canvas.FillRect(Rect);
    DrawText(Canvas.Handle,PChar(s),Length(s),Rect,
             DT_SINGLELINE or DT_CENTER or DT_VCENTER);
    end;{with StringGrid1}

finde die Lösung ist einfach und übersichtlich.

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )