Results 1 to 4 of 4

Thread: [2005]ListBox Background Image???

  1. #1

    Thread Starter
    Addicted Member sweet_dreams's Avatar
    Join Date
    Apr 2005
    Location
    Poland, Lodz
    Posts
    189

    Question [2005]ListBox Background Image???

    Hi all,

    Is it possible to set image as a ListBoxs background??? ListBox doesn't have BackGroundImage property, so is it possible to be done?

    please help,
    sweet_dreams
    Last edited by sweet_dreams; Jul 15th, 2006 at 05:34 AM.
    using VB 2010 .NET Framework 4.0; MS Office 2010; SQL Server 2008 R2 Express Edition | Remember to mark resolved threads and rate useful posts.

  2. #2
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: [2005]ListBox Background Image???

    you have to make up your own ListBox:
    VB Code:
    1. Public Class MyListBox
    2.     Inherits ListBox
    3.     Private BGImage As Image
    4.     Public Overrides Property BackgroundImage() As Image
    5.         Get
    6.             Return BGImage
    7.         End Get
    8.         Set(ByVal Value As Image)
    9.             BGImage = Value
    10.         End Set
    11.     End Property
    12.     Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
    13.         Dim g As Graphics = e.Graphics
    14.         g.DrawImage(BGImage, New PointF(0, 0))
    15.     End Sub
    16.  
    17.     Protected Overrides Sub Refre****em(ByVal index As Integer)
    18.  
    19.     End Sub
    20.  
    21.     Protected Overrides Sub SetItemsCore(ByVal items As System.Collections.IList)
    22.  
    23.     End Sub
    24. End Class

    EDIT: The stars refer to "Refresh Item"
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  3. #3
    Junior Member
    Join Date
    Sep 2006
    Posts
    16

    Question Re: [2005]ListBox Background Image???

    Quote Originally Posted by ComputerJy
    you have to make up your own ListBox:
    VB Code:
    1. Public Class MyListBox
    2.     Inherits ListBox
    3.     Private BGImage As Image
    4.     Public Overrides Property BackgroundImage() As Image
    5.         Get
    6.             Return BGImage
    7.         End Get
    8.         Set(ByVal Value As Image)
    9.             BGImage = Value
    10.         End Set
    11.     End Property
    12.     Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
    13.         Dim g As Graphics = e.Graphics
    14.         g.DrawImage(BGImage, New PointF(0, 0))
    15.     End Sub
    16.  
    17.     Protected Overrides Sub Refre****em(ByVal index As Integer)
    18.  
    19.     End Sub
    20.  
    21.     Protected Overrides Sub SetItemsCore(ByVal items As System.Collections.IList)
    22.  
    23.     End Sub
    24. End Class

    EDIT: The stars refer to "Refresh Item"
    I am not very proficient in subclassing and / or building custom controls. Can you pl elaborate how to use the above code ?

  4. #4
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: [2005]ListBox Background Image???

    Just put that code in a file, save it. And instead of declaring
    VB Code:
    1. Friend WithEvents ListBox1 As New ListBox
    use
    VB Code:
    1. Friend WithEvents ListBox1 As New MyListBox
    And use ListBox1.BackgroundImage to set the Image property
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width