Autor Beitrag
moloch
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 451

Win 2000
D5 Prof
BeitragVerfasst: Di 28.09.04 09:56 
Hallo Leute,
ich kriege einen zeilenumbruch im stringgrid hin:

ausblenden Delphi-Quelltext
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:
procedure GridAlignment(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
      or DT_WORDBREAK);
    if Alignment = taCenter then
      DrawText(Grid.Canvas.Handle, PChar(TextOut), StrLen(PChar(TextOut)), Rect, DT_CENTER
      or DT_WORDBREAK);
    if Alignment = taRightJustify then
      DrawText(Grid.Canvas.Handle, PChar(TextOut), StrLen(PChar(TextOut)), Rect, DT_RIGHT
      or DT_WORDBREAK);
  end;
end;


ABER: Dieser Zeilenumbruch tritt ja immer nur dann ein wenn ein Leerzeichen vorhanden ist. Gibt es eine Möglichkeit rauszufinden welcher buchstabe ("pos") nicht mehr ins feld passt, damit ich da dann ein leerzeichen und ein "-" einsetzen kann???

mfg
moloch

Moderiert von user profile iconChristian S.: 144 Beiträge und kennt die Delphi-Tags noch nicht :roll: ;-)
.Chef
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1112



BeitragVerfasst: Di 28.09.04 10:12 
Ja, du kannst mit Canvas.Textwidth die Breite bestimmen. Musst du dann solange mit einem Zeichen weniger wiederholen, bis es passt.

_________________
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 "="!
moloch Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 451

Win 2000
D5 Prof
BeitragVerfasst: Di 28.09.04 12:42 
also für den zeilenumbruch brauche ich ja ein leerzeichen.
also müsste ich in den string an den jeweiligen stellen ein leerzeichen einsetzen.
wie kann ich das machen?

mfg
moloch
.Chef
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1112



BeitragVerfasst: Di 28.09.04 12:51 
Gewöhn dir mal an, Fragen immer nur einmal zu stellen! :motz:

Hier gehts weiter!

_________________
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 "="!
Tino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Veteran
Beiträge: 9839
Erhaltene Danke: 45

Windows 8.1
Delphi XE4
BeitragVerfasst: Mi 29.09.04 17:01 
.Chef hat folgendes geschrieben:
Gewöhn dir mal an, Fragen immer nur einmal zu stellen! :motz:

Hier gehts weiter!

Das sind doch zwei unterschiedliche Fragen?!?
GSE
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 740

Win 2k, Win XP Pro
D5 Prof, D6 Ent, D2k5 PE
BeitragVerfasst: Mi 29.09.04 17:06 
.Chef hat gemeint, er hat ja schonmal gefragt wie man ein Zeichen an eine bestimmte Stelle setzt

mfg
GSE

_________________
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs
and the universe trying to produce bigger and better idiots. So far, the universe is winning. (Richard Cook)
DelphiJogi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 19

Win11
Delphi 10.4
BeitragVerfasst: Mi 18.10.23 21:01 
Hallo User,

ausblenden Delphi-Quelltext
1:
2:
DrawText(Grid.Canvas.Handle, PChar(TextOut), StrLen(PChar(TextOut)), Rect, DT_RIGHT);
DrawText(Grid.Canvas.Handle, PChar(TextOut), StrLen(PChar(TextOut)), Rect, DT_LEFT);

Obige Formatierungen funktionieren hervorragend. Wie kann ich nun noch den Rect.Top Wert integrieren?
Der Text soll entsprechend der Zeilenhöhe mittig ausgegeben werden.

Moderiert von user profile iconTh69: Delphi-Tags hinzugefügt
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19274
Erhaltene Danke: 1740

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Do 19.10.23 06:35 
Du kannst die Textgröße mit DT_CALCRECT bestimmen und dann Rect.Top zur Ausgabe entsprechend setzen. Eine automatische vertikale Zentrierung ist leider nicht möglich, wenn der Text aus mehr als einer Zeile besteht (bei einer Zeile mit DT_SINGLELINE ginge es mit DT_VCENTER).

Für diesen Beitrag haben gedankt: DelphiJogi
DelphiJogi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 19

Win11
Delphi 10.4
BeitragVerfasst: Fr 20.10.23 18:07 
Danke Sebastian, bin erstmal weiter gekommen.
DelphiJogi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 19

Win11
Delphi 10.4
BeitragVerfasst: Do 26.10.23 18:11 
Hallo User,
wie kann die Farbe der Linien eines StringGrids geändert werden?
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19274
Erhaltene Danke: 1740

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Do 26.10.23 22:24 
Du zeichnest die Linien der einzelnen Zelle im OnDrawCell so wie du sie möchtest.
DelphiJogi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 19

Win11
Delphi 10.4
BeitragVerfasst: Fr 27.10.23 19:17 
user profile iconjaenicke hat folgendes geschrieben Zum zitierten Posting springen:
Du zeichnest die Linien der einzelnen Zelle im OnDrawCell so wie du sie möchtest.

Danke, das ist mir aber soweit klar!

Ich kann die FontFarbe und die Zellenfarbe bestimmen ...
ausblenden Delphi-Quelltext
1:
2:
3:
Grid.Canvas.Brush.Color := clRed;
Grid.Canvas.Font.Color:=clWhite;
Grid.Canvas.FillRect(Rect);

... aber nicht die Farbe des Gitters.
Im Grid.DrawingStyle:= gdsGradient werden die Zellenrahmen hell gezeichnet. Im gdsClassic hingegen dunkel.

Wie kann ich nun die Farbe der Zellen-Rahmen beinflussen?

Moderiert von user profile iconTh69: Delphi-Tags hinzugefügt
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19274
Erhaltene Danke: 1740

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Fr 27.10.23 21:36 
Du hast nur die Farbe des Hintergrundes und der Schriftart gesetzt. Wie wäre es, wenn du noch die Farbe der Linien (Grid.Canvas.Pen.Color) setzt?

Für diesen Beitrag haben gedankt: DelphiJogi
DelphiJogi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 19

Win11
Delphi 10.4
BeitragVerfasst: Fr 27.10.23 22:55 
Danke, das war es was ich brauchte!
DelphiJogi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 19

Win11
Delphi 10.4
BeitragVerfasst: Sa 28.10.23 20:15 
user profile iconjaenicke hat folgendes geschrieben Zum zitierten Posting springen:
Du hast nur die Farbe des Hintergrundes und der Schriftart gesetzt. Wie wäre es, wenn du noch die Farbe der Linien (Grid.Canvas.Pen.Color) setzt?

Da habe ich mich wohl zu früh gefreut. Leider hat hat das setzen von Grid.Canvas.Pen.Color keinerlei Auswirkung.

Moderiert von user profile iconTh69: Delphi-Tags hinzugefügt
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19274
Erhaltene Danke: 1740

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 28.10.23 23:50 
Verwendest du denn auch Rectangle statt FillRect? FillRect zeichnet ja explizit nur den Hintergrund des Rechtecks wie der Name schon sagt.

Für diesen Beitrag haben gedankt: DelphiJogi
DelphiJogi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 19

Win11
Delphi 10.4
BeitragVerfasst: So 29.10.23 22:52 
Danke Sebastian für deine schnelle und kompetente Hilfe!