Autor Beitrag
Kurdt67
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 30

WIN XP
D7 Pers
BeitragVerfasst: So 18.09.05 13:29 
Also ich habe eine menge Text in eine Listbox zu schreiben.Und ich will das der das alles ordentlich anzeigt. also sprich nen zeilenumbruch immer automatisch gemacht wird. geht das?? er darf aber auch die wörter nicht trennen.
Grishnak
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 221

Windows XP Home
Delphi 7 PE, Delphi 2005 PE
BeitragVerfasst: So 18.09.05 13:53 
Wann soll den ein Zeilenumbruch zwischen Wörtern erfolgen? Jeweils zwischen allen Wörtern oder wenn eine Zeile der ListBox voll ist?

_________________
Mach' etwas idiotensicher und irgendjemand erfindet einen besseren Idioten!
Kurdt67 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 30

WIN XP
D7 Pers
BeitragVerfasst: So 18.09.05 13:55 
Ja der Zeilenumbrauch soll dann erfolgen wenn die Zeile der ListBox zu ende ist. Weil die
is ja nur ne bestimmte breite.
Grishnak
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 221

Windows XP Home
Delphi 7 PE, Delphi 2005 PE
BeitragVerfasst: So 18.09.05 14:03 
Warum eine ListBox? Nimm doch ein TMemo-Objekt!

_________________
Mach' etwas idiotensicher und irgendjemand erfindet einen besseren Idioten!
Kurdt67 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 30

WIN XP
D7 Pers
BeitragVerfasst: So 18.09.05 14:23 
hab jetzt nen Memo genommen, geht besser, DANKE
Sprint
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 849



BeitragVerfasst: So 02.10.05 16:10 
In der Newsgroup borland.public.delphi.winapi habe ich einen Beitrag von Peter Below (Message-ID: <VA.00003a9a.01698837@petersnewbox>) vom 19.09.1999. Diese TListBox Komponente macht dann einen Zeilenumbruch, wenn der Text länger ist, als die TListBox breit ist.

[meta]TListBox Zeilenumbruch WordWrap MultiLine TMultilineListbox Peter Below TeamB[/meta]
Einloggen, um Attachments anzusehen!
_________________
Ciao, Sprint.
Sprint
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 849



BeitragVerfasst: So 02.10.05 22:56 
Hab das mal so angepasst, das man keine zusätzliche Komponente braucht. Dazu benötigt man die Ereignisse OnMeasureItem und OnDrawItem (TListBox). Außerdem muss die Eigenschaft "Style" auf lbOwnerDrawVariable gesetzt werden.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure TForm1.FormCreate(Sender: TObject);
begin

  ListBox1.Style := lbOwnerDrawVariable;
  ListBox1.Canvas.Font := ListBox1.Font;

end;

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
procedure TForm1.ListBox1MeasureItem(Control: TWinControl; Index: Integer; var Height: Integer);
var
  Format: Integer;
  Rect: TRect;
begin

  with (Control as TListBox) do
  begin
    Format := DrawTextBiDiModeFlags(DT_WORDBREAK or DT_NOPREFIX or DT_CALCRECT or DT_LEFT);
    Rect := Classes.Rect(00, ClientWidth - 41);
    DrawText(Canvas.Handle, PChar(Items[Index]), Length(Items[Index]), Rect, Format);
  end;
  if Rect.Bottom > 251 then
    Height := 255
  else
    Height := Rect.Bottom + 4;

end;

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);
var
  Format: Integer;
begin

  with (Control as TListBox) do
  begin
    Canvas.FillRect(Rect);
    Format := DrawTextBiDiModeFlags(DT_WORDBREAK or DT_NOPREFIX or DT_LEFT);
    Rect.Left := Rect.Left + 2;
    Rect.Top := Rect.Top + 2;
    DrawText(Canvas.Handle, PChar(Items[Index]), Length(Items[Index]), Rect, Format);
  end;

end;

_________________
Ciao, Sprint.