Einzelnen Beitrag anzeigen

Benutzerbild von Lannes
Lannes

Registriert seit: 30. Jan 2005
Ort: Münster
745 Beiträge
 
Delphi 3 Professional
 
#6

Re: Listbox von unten füllen

  Alt 20. Okt 2005, 23:33
Hallo,

wie wäre es den damit ,etwas Abwechslung ist ja nicht schlecht am späten Abend
Delphi-Quellcode:
procedure TForm1.FormCreate(Sender: TObject);
begin
  ListBox1.Style := lbOwnerDrawFixed;
  ListBox1.IntegralHeight := True;
  ButtonClearClick(self);//damit beim Start gleich alles ok ist
end;

//ListBox mit leeren Zeilen bis zum Ende füllen
procedure TForm1.ButtonClearClick(Sender: TObject);
var z : integer;
begin
  ListBox1.Clear;
  for z := 0 to Round(ListBox1.Height/ListBox1.ItemHeight)-1 do
    ListBox1.Items.Add('');
  //Tag wird zum Nachhalten der beschriebenen Items gebraucht
  ListBox1.Tag := Round(ListBox1.Height/ListBox1.ItemHeight)-1;
end;

procedure TForm1.ButtonEintragClick(Sender: TObject);
begin
  if ListBox1.Tag = 0 then//oben angekommen
    begin
    ListBox1.Items[0] := Edit1.Text;
    ListBox1.Items.Insert(0,'');//leere Zeile oben anlegen für kommende Eintrag
    end
    else
      begin
      ListBox1.Items[ListBox1.Tag] := Edit1.Text;>//nach oben füllen
      ListBox1.Tag := ListBox1.Tag-1;
      end;
end;
//damit man nicht oberhalb der Einträge eine Markierung sieht
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
begin
    if odFocused in State then
      begin
      if Listbox1.Items[Index] = 'then
        Listbox1.Canvas.Brush.Color := Listbox1.Color;
      Listbox1.Canvas.FillRect(Rect);
      Listbox1.Canvas.TextOut(Rect.Left,Rect.Top,Listbox1.Items[Index]);
      if Listbox1.Items[Index] = 'then
        begin
        ListBox1.ItemIndex := -1;
        DrawFocusRect(Listbox1.Canvas.Handle,Rect);//Focusrechteck entfernen
        end;
      end
      else
        begin
        Listbox1.Canvas.FillRect(Rect);
        Listbox1.Canvas.TextOut(Rect.Left,Rect.Top,Listbox1.Items[Index]);
        end;
end;
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
  Mit Zitat antworten Zitat