Listbox ta Otomatik boyutlandırma işlemi
| ||||
unit MutliLineListBox;
interface
uses Windows, Graphics, Messages, SysUtils, Classes, Controls, StdCtrls;
type
TMutliLineListBox = class(TListBox)
private
{ Private declarations }
FMultiLine: Boolean;
procedure SetMultiLine(const Value: Boolean);
protected
{ Protected declarations }
procedure DrawItem(Index: Integer; Rect: TRect; State: TOwnerDrawState); override;
procedure MeasureItem(Index: Integer; var Height: Integer); override;
public
{ Public declarations }
published
{ Published declarations }
property MultiLine: Boolean read FMultiLine write SetMultiLine;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents(‘Standard’, [TMutliLineListBox]);
end;
{ TMutliLineListBox }
procedure TMutliLineListBox.DrawItem(Index: Integer; Rect: TRect; State: TOwnerDrawState);
var
s: string;
begin
if (FMultiLine) then
begin
Canvas.Font := Font;
if (odSelected in State) then Canvas.Font.Color := clHighlightText;
Canvas.FillRect(Rect);
s := Items[ Index ];
DrawText(Canvas.Handle, PChar(s), Length(s), Rect, DT_WORDBREAK);
end
else
inherited;
end;
procedure TMutliLineListBox.MeasureItem(Index: Integer; var Height: Integer);
var
s: string;
h: Integer;
r: TRect;
begin
if (FMultiLine) then
begin
h := Height;
Canvas.Font := Font;
s := Items[ Index ];
r := ItemRect(Index);
DrawText(Canvas.Handle, PChar(s), Length(s), r, DT_CALCRECT or DT_WORDBREAK);
Height := (r.Bottom – r.Top);
if (Height < h) then Height := h;
end
else
inherited;
end;
procedure TMutliLineListBox.SetMultiLine(const Value: Boolean);
begin
if (FMultiLine <> Value) then
begin
FMultiLine := Value;
if (FMultiLine) then
Style := lbOwnerDrawVariable
else
Style := lbStandard;
end;
end;
end.
administrator2009-08-30 15:15:07
Benzer Yazılar:
- Ekran Klavyesi
- Listbox İtemlerinin Sırasını Mause ile sürükleyerek Değiştirmek
- Delphide Yazılmış Kaynak Kodlar
- Tüm Dosya ve Klasörlerin Listesini Almak
- CxGrid de Arama Yapmak
- Bilgisayardaki Sürücü Listesini Almak
- Dosya Uzantısından Programın Tespiti
- Yazılan Fiyatı Metine Çevirmek
- Ağ daki Bilgisayarlara Ping Atmak
- Metnin İçerisindeki Kelime Sayısını Bulan Kod
Eğer yazıyı beğendiyseniz ya da ekleyecekleriniz varsa, lütfen yorumunuz yazın veya RSS aboneliği ile yeni yazılardan anında haberdar olun.




















