تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
تلوين ال ListBox
#1
السلام عليكم و رحمة الله و بركاته

تلوين ال ListBox





أولا قم بتفعيل ال Owner Draw :

دلفي :

PHP كود :
self.ListBox1.Style := TListBoxStyle.lbOwnerDrawFixed 
دوت نت :


PHP كود :
listBox1.DrawMode DrawMode.OwnerDrawFixed 
الآن كل العمل سيتم في الحدث DrawItem :

نقوم بفحص ترتيب ال item , اذا كان الترتيب زوجي (أي باقي القسمة على 2 يساوي 0) نقوم بتلوين ال Item باللون 1 , أما اذا كان الترتيب فردي (أي باقي القسمة لعى 2 لا يساوي صفر) نقوم بتلوين ال Item باللون الثاني ..

دلفي :
PHP كود :
procedure TMain.ListBox1DrawItem(ControlTWinControlIndexInteger;
aRectTRectStateTOwnerDrawState);
var 
myListBox:TListBox;
begin
myListBox
:=TListBox(Control) ;
if 
index mod 2 0 then
// First Color (index is pair)
myListBox.Canvas.Brush.Color := clAqua else
// Second Color (index is impair)
myListBox.Canvas.Brush.Color:= clYellow;
// Draw Rectangle
myListBox.Canvas.FillRect(aRect);
// Set Font Color to Black
myListBox.Canvas.Font.Color :=clblack;
// Draw Items Text
myListBox.Canvas.TextOut(aRect.Left ,aRect.Top ,myListBox.Items [index]);

if 
odSelected in State then
myListBox
.Canvas.DrawFocusRect(aRect);

end
csharp :
PHP كود :
private void listBox1_DrawItem(object senderDrawItemEventArgs e)
{
ListBox myListBox = (ListBox)sender;
SolidBrush sb = new SolidBrush (Color.White );
if (
e.Index == 0)
sb.Color Color.Aqua;
else
sb.Color Color.Yellow;
e.Graphics.FillRectangle(sbe.Bounds);
e.Graphics.DrawString(myListBox.Items[e.Index].ToString (),e.Font,new SolidBrush (Color.Black ),e.Bounds );
if ((
e.State DrawItemState.Selected) == DrawItemState.Selected)
e.DrawFocusRectangle();

Vb.Net :
PHP كود :
Private Sub ListBox1_DrawItem(sender As ObjectAs DrawItemEventArgsHandles ListBox1.DrawItem
Dim myListBox 
As ListBox CType(senderListBox)
Dim sb As SolidBrush = New SolidBrush(Color.White)
If 
e.Index Mod 2 0 Then
sb
.Color Color.Aqua
Else
sb.Color Color.Yellow
End 
If
e.Graphics.FillRectangle(sbe.Bounds)
e.Graphics.DrawString(myListBox.Items(e.Index).ToStringe.Font, New SolidBrush(Color.Black), e.Bounds)
If (
e.State And DrawItemState.Selected) = DrawItemState.Selected Then
e
.DrawFocusRectangle()
End If
End Sub 
الرد }}}
تم الشكر بواسطة:


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


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