Note that there are some explanatory texts on larger screens.

plurals
  1. PORefining a custom listbox control
    primarykey
    data
    text
    <p>I have made a sort of custom list box and have included the ability to add an image to each item. I want to be able to change these images one by one at will and am not too sure on how to go about it. At the moment you can only select which image you would like in every item.</p> <pre><code>Public Class CustomListBox Public label As Label Public pic As PictureBox Public panel As Panel Public itemID As String Public itemCollection As New Collection Public bgColor As Color Public txtEnterColor As Color = Color.FromArgb(80, 80, 80) Public txtColor As Color = Color.FromArgb(150, 150, 150) Public bgEntercolor As Color = Color.FromArgb(230, 230, 230) Public x, y, paddingInt As Integer Public itemHeight As Integer = 40 Public image As Image = My.Resources.FavNone Public Event Item_Clicked() Private Property ItemBackColor As Color Get Return BackColor End Get Set(ByVal value As Color) bgColor = value End Set End Property Private Property ItemPadding As Padding Get Return Padding End Get Set(ByVal value As Padding) Padding = value End Set End Property Public Property HoverBackColor As Color Get Return bgEntercolor End Get Set(ByVal value As Color) bgEntercolor = value End Set End Property Public Property ItemImage As Image Get Return image End Get Set(ByVal value As Image) image = value End Set End Property Public Property HoverTextColor As Color Get Return txtEnterColor End Get Set(ByVal value As Color) txtEnterColor = value End Set End Property Public Property TextColor As Color Get Return txtColor End Get Set(ByVal value As Color) txtColor = value End Set End Property Public Property TrueItemHeight As Integer Get Return itemHeight End Get Set(ByVal value As Integer) itemHeight = value End Set End Property Public Sub UpdateItems() For Each item As String In itemCollection label = New Label pic = New PictureBox panel = New Panel With pic .Width = itemHeight .Height = itemHeight .SizeMode = PictureBoxSizeMode.Zoom .Image = image End With With label .BackColor = (bgColor) .ForeColor = (txtColor) .Width = Me.Width - itemHeight .Height = itemHeight .Tag = item .Height = itemHeight .Padding = ItemPadding .Text = item .Left = itemHeight .TextAlign = ContentAlignment.MiddleLeft AddHandler label.MouseEnter, AddressOf Item_Enter AddHandler label.MouseLeave, AddressOf Item_Leave AddHandler label.MouseUp, AddressOf Item_Mousedown End With With panel .Location = New Point(x, y) .Width = Me.Width .Height = itemHeight .Controls.Add(pic) .Controls.Add(label) y += .Height + paddingInt End With Me.Controls.Add(panel) Next End Sub Private Sub Item_Enter(ByVal sender As Label, ByVal e As EventArgs) sender.BackColor = (bgEnterColor) sender.ForeColor = (txtEnterColor) itemID = sender.Tag End Sub Private Sub Item_Leave(ByVal sender As Label, ByVal e As EventArgs) sender.BackColor = (bgColor) sender.ForeColor = (txtColor) End Sub Private Sub Item_Mousedown(ByVal sender As Label, ByVal e As MouseEventArgs) Select Case e.button Case Windows.Forms.MouseButtons.Left RaiseEvent Item_Clicked() End Select End Sub End Class </code></pre> <p>I know I'll need to add something into the click event of the items.Possible set a variable with the index number of the label, maybe...?</p> <p>Also, how do I get auto-suggestions when typing the code. For example, I want to be able to type CustomListBox1.itemCollection.add("Text", imageSrc)...etc I just have no idea what to type into Google apart from looking through loads of custom controls until I find one that includes this.</p> <h1>EDIT</h1> <p>I have looked into <a href="http://www.vbforums.com/showthread.php?p=3703233" rel="nofollow">this</a> custom Listbox.</p> <p>I tried to add a MouseMove event to each item so thought it would be as easy as placing this:</p> <pre><code>Private Sub HoverItem(ByVal item As ColorListboxItem, ByVal e As MouseEventArgs) msgbox(1) End Sub </code></pre> <p>...in the "Methods" region and then </p> <pre><code> AddHandler .mousemove, AddressOf HoverItem </code></pre> <p>to the "OnDrawItem" sub. Unfortunately for me, it obviously isn't that easy as no msgbox shows. Could anybody with experience on this control give a bit of insight as to how it works. And maybe an example of the MouseMove event so then I'll get an idea on how to add in more events (Mouseleave, DblClick...etc)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload