30-08-14, 04:31 PM
الكود التالي عبارة عن كونترول تم توريثه من ListBox و اعتقد انك من الممكن ان تستخدمه لعرض الصور الخاصة بكل موظف .....لقد قمت بضبط ارتفاع الصورة ليكون في الحدود المعقولة للإستخدام لكن يمكنك ضبك اقصي ارتفاع للكونترول كما يحلو لك و يناسب احتياجاتك
الكونترول مزود بخاصية ImageList و يقوم برسم الصور و التكست بالإضافة الي اشياء أخري لكن يمكنك ان تستخدمه لعرض الصور فقط
الكونترول مزود بخاصية ImageList و يقوم برسم الصور و التكست بالإضافة الي اشياء أخري لكن يمكنك ان تستخدمه لعرض الصور فقط
كود :
Public Class ImageListBox
Inherits ListBox
Private imgs As ImageList = New ImageList()
Public Property ImageList() As ImageList
Get
Return Me.imgs
End Get
Set(value As ImageList)
Me.imgs = value
End Set
End Property
Public Sub New()
Me.DrawMode = DrawMode.OwnerDrawFixed
MyBase.IntegralHeight = False
MyBase.ItemHeight = 150
End Sub
Protected Overrides Sub OnDrawItem(e As DrawItemEventArgs)
e.DrawBackground()
e.DrawFocusRectangle()
If e.Index < 0 OrElse e.Index >= MyBase.Items.Count Then
e.Graphics.DrawString(Me.Text, e.Font, New SolidBrush(e.ForeColor), CSng((e.Bounds.Left + Me.imgs.ImageSize.Width)), CSng(e.Bounds.Top))
Else
If MyBase.Items(e.Index).[GetType]() Is GetType(ImageListItem) Then
Dim imageListItem As ImageListItem = CType(MyBase.Items(e.Index), ImageListItem)
Dim color As Color = If((imageListItem.ForeColor <> color.FromKnownColor(KnownColor.Transparent)), imageListItem.ForeColor, e.ForeColor)
Dim font As Font = If(imageListItem.Mark, New Font(e.Font, FontStyle.Bold), e.Font)
If imageListItem.ImageIndex <> -1 Then
Me.ImageList.Draw(e.Graphics, e.Bounds.Left, e.Bounds.Top, imageListItem.ImageIndex)
e.Graphics.DrawString(imageListItem.Text, font, New SolidBrush(color), CSng((e.Bounds.Left + Me.imgs.ImageSize.Width)), CSng(e.Bounds.Top))
Else
e.Graphics.DrawString(imageListItem.Text, font, New SolidBrush(color), CSng((e.Bounds.Left + Me.imgs.ImageSize.Width)), CSng(e.Bounds.Top))
End If
Else
e.Graphics.DrawString(MyBase.Items(e.Index).ToString(), e.Font, New SolidBrush(e.ForeColor), CSng((e.Bounds.Left + Me.imgs.ImageSize.Width)), CSng(e.Bounds.Top))
End If
End If
MyBase.OnDrawItem(e)
End Sub
End Class
Public Class ImageListItem
Private _forecolor As Color = Color.FromKnownColor(KnownColor.Transparent)
Private _mark As Boolean
Private _imageindex As Integer = -1
Private _tag As Object
Private _text As String
Public Property ForeColor() As Color
Get
Return Me._forecolor
End Get
Set(value As Color)
Me._forecolor = value
End Set
End Property
Public Property ImageIndex() As Integer
Get
Return Me._imageindex
End Get
Set(value As Integer)
Me._imageindex = value
End Set
End Property
Public Property Mark() As Boolean
Get
Return Me._mark
End Get
Set(value As Boolean)
Me._mark = value
End Set
End Property
Public Property Tag() As Object
Get
Return Me._tag
End Get
Set(value As Object)
Me._tag = value
End Set
End Property
Public Property Text() As String
Get
Return Me._text
End Get
Set(value As String)
Me._text = value
End Set
End Property
Public Sub New()
End Sub
Public Sub New(Text As String)
Me._text = Text
End Sub
Public Sub New(imageIndex As Integer)
Me._imageindex = imageIndex
End Sub
Public Sub New(Text As String, ImageIndex As Integer)
Me._text = Text
Me._imageindex = ImageIndex
End Sub
Public Sub New(Text As String, ImageIndex As Integer, Tag As String)
Me._text = Text
Me._imageindex = ImageIndex
Me._tag = Tag
End Sub
Public Sub New(Text As String, ImageIndex As Integer, Mark As Boolean)
Me._text = Text
Me._imageindex = ImageIndex
Me._mark = Mark
End Sub
Public Sub New(Text As String, ImageIndex As Integer, Mark As Boolean, ForeColor As Color)
Me._text = Text
Me._imageindex = ImageIndex
Me._mark = Mark
Me._forecolor = ForeColor
End Sub
Public Sub New(Text As String, ImageIndex As Integer, Mark As Boolean, ForeColor As Color, Tag As Object)
Me._text = Text
Me._imageindex = ImageIndex
Me._mark = Mark
Me._forecolor = ForeColor
Me._tag = Tag
End Sub
Public Overrides Function ToString() As String
Return Me._text
End Function
End Class
