Fix ListBox – VCL Style
#1
السلام عليكم و رحمة الله و بركاته

هل مليت من عدم دعم ال ListBox ل VCL Style ؟ , أكيد نعم Smile
كود :
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
حل المشكلة سهل فكل ماعليك فعله هو أن تقوم باعادة الرسم في الحدث DrawItem الخاص بال ListBox , لكن قبل هذا يتوجب عليك تفعيل ال Owner Draw لل ListBox حتى نتمكن من الرسم
اذ أن الوينداوز لا يسمح لك بالرسم لا بتفعيل ال Owner Draw . فكما تعلم فالوينداوز مسؤول عن رسم أغلب الأدوات .
الدواء Smile
أولا قم باضافة المكتبة Themes للمشروع
PHP كود :
uses Vcl.Themes; 
ثم نقوم باعادة صياغة الكلاس ListBox
PHP كود :
type TListBox =class (vcl.stdctrls.TListBox )
public
 
constructor Create(AOwner: TComponent); override;
protected
 
procedure DrawItem(Index: Integer; Rect: TRect; State: TOwnerDrawState);override;
end; 
نقوم بتفعيل ال Owner Draw في ال constructor الخاص بالحدث "Create"
PHP كود :
constructor TListBox.Create(AOwner: TComponent);
 
begin
 inherited
;
 
// Owner Draw = True
 
self.Style:=TListBoxStyle.lbOwnerDrawFixed ;
 
end; 
ثم نقوم باعادة رسم ال Items في الحدث DrawItem
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; 


الملفات المرفقة
.rar   Fix ListBox - VCL Style.rar (الحجم : 186.78 ك ب / التحميلات : 54)
الرد


التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم