Kylix
Tips

NEW TIPS
Database (135)
Files (612)
Forms (606)
Graphic (536)
IDE (456)
Indy (433)
Internet / LAN (590)
IntraWeb (443)
Kylix (447)
Math (561)
Misc (591)
Multimedia (496)
Objects/
ActiveX (503)

OpenTools API (438)
Printing (459)
Strings (583)
System (721)
VCL (586)

Search Tip
Top15
Add new Tip

Forum

...set TListBox Items right aligned?
Author: Rainer Kümmerle
Homepage: http://www.thinklazy.de
[ Print tip ]    

Tip Rating (0):  
     



procedure TForm1.FormCreate(Sender: TObject);
begin
  
// Oder im Objektinspektor einstellen
  // Or set in object inspector
  
ListBox1.Style := lbOwnerDrawFixed;
end;

procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
var
  
l: Integer; 
  t: String;
begin
  with 
ListBox1 do
  begin
    
Canvas.FillRect(Rect);
    t := Items[Index]; 
    l := Rect.Right - Canvas.TextWidth(t) - 1;
    Canvas.TextOut(l, Rect.Top, t);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  
ListBox1.Items.Add(Edit1.Text);
end;

Rate this tip:

poor
very good


Copyright © Torry's Delphi Pages Torry's Delphi Pages Maintained by Simon Grossenbacher Notes? Comments? Feel free to send... Copyright © 1996-2001