03-10-2012, 06:47 PM
السلام عليكم و رحمة الله و بركاته
هل مليت من عدم دعم ال ListBox ل VCL Style ؟ , أكيد نعم
اليوم قمت بحل المشكلة
حل المشكلة سهل فكل ماعليك فعله هو أن تقوم باعادة الرسم في الحدث DrawItem الخاص بال ListBox , لكن قبل هذا يتوجب عليك تفعيل ال Owner Draw لل ListBox حتى نتمكن من الرسم
اذ أن الوينداوز لا يسمح لك بالرسم لا بتفعيل ال Owner Draw . فكما تعلم فالوينداوز مسؤول عن رسم أغلب الأدوات .
الدواء
أولا قم باضافة المكتبة Themes للمشروع
ثم نقوم باعادة صياغة الكلاس ListBox
نقوم بتفعيل ال Owner Draw في ال constructor الخاص بالحدث "Create"
ثم نقوم باعادة رسم ال Items في الحدث DrawItem
هل مليت من عدم دعم ال ListBox ل VCL Style ؟ , أكيد نعم

كود :
http://delphinews.files.wordpress.com/2012/10/simple-listbox.jpgكود :
http://delphinews.files.wordpress.com/2012/10/listbox.jpgكود :
http://delphinews.files.wordpress.com/2012/10/listbox2.jpgاذ أن الوينداوز لا يسمح لك بالرسم لا بتفعيل ال Owner Draw . فكما تعلم فالوينداوز مسؤول عن رسم أغلب الأدوات .
الدواء

أولا قم باضافة المكتبة Themes للمشروع
PHP كود :
uses Vcl.Themes;
PHP كود :
type TListBox =class (vcl.stdctrls.TListBox )
public
constructor Create(AOwner: TComponent); override;
protected
procedure DrawItem(Index: Integer; Rect: TRect; State: TOwnerDrawState);override;
end;
PHP كود :
constructor TListBox.Create(AOwner: TComponent);
begin
inherited;
// Owner Draw = True
self.Style:=TListBoxStyle.lbOwnerDrawFixed ;
end;
PHP كود :
procedure TListBox.DrawItem(Index: Integer; Rect: TRect; State: TOwnerDrawState);
Var
sStyle : TCustomStyleServices;
ThemeDetails :TThemedElementDetails ;
begin
sStyle :=StyleServices;
// Check if style is windows style
if sStyle.IsSystemStyle then begin
inherited;
exit;
end;
// Get details
ThemeDetails:=sStyle.GetElementDetails ( vcl.Themes.TThemedMenu.tmMenuBarItemHot );
// Check if item is selected
if odSelected in State then begin
// Draw the new rectangle
sStyle.DrawElement(canvas.Handle,ThemeDetails,rect) ;
inc( Rect.Left,2);
// Draw items text
sStyle.DrawText(Canvas.Handle, ThemeDetails, self.Items [index] , Rect, [tfLeft, tfSingleLine, tfVerticalCenter])
end
else begin
// fill unselected items
Canvas.FillRect(Rect);
// Get details
ThemeDetails := StyleServices.GetElementDetails(tlListItemNormal);
inc( Rect.Left,2);
// Draw items text
sStyle.DrawText(Canvas.Handle, ThemeDetails, self.Items [index] , Rect, [tfLeft, tfSingleLine, tfVerticalCenter]);
end;
end;

