2012-02-14 65 views

回答

3

此链接可以帮助你:http://www.codeproject.com/Articles/10670/Image-ComboBox-Control

编辑,这样做在VB中,设置您的组合为的OwnerDraw,然后:

protected Overrides Sub OnDrawItem(ByVal e As System.Windows.Forms.DrawItemEventArgs) 

    e.DrawBackground() 
    e.DrawFocusRectangle() 
    Dim item As New ComboBoxIconItem 
    Dim imageSize As New Size 
    imageSize = ListaImg1.ImageSize 
    Dim bounds As New Rectangle 
    bounds = e.Bounds 
    Try 
     item = Me.Items(e.Index) 
     If (item.ImageIndex <> -1) Then 
      Me.ImageList.Draw(e.Graphics, bounds.Left, _ 
       bounds.Top, item.ImageIndex) 
      e.Graphics.DrawString(item.Text, e.Font, _ 
       New SolidBrush(e.ForeColor), bounds.Left + _ 
       imageSize.Width, bounds.Top) 
     Else 
      e.Graphics.DrawString(item.Text, e.Font, _ 
       New SolidBrush(e.ForeColor), bounds.Left, _ 
       bounds.Top) 
     End If 
     Catch ex As Exception 
     If (e.Index <> -1) Then 
      e.Graphics.DrawString(Items(e.Index).ToString(), e.Font, _ 
       New SolidBrush(e.ForeColor), bounds.Left, bounds.Top) 
     Else 
      e.Graphics.DrawString(Text, e.Font, _ 
       New SolidBrush(e.ForeColor), bounds.Left, bounds.Top) 
     End If 
    End Try 
    MyBase.OnDrawItem(e) 
End Sub 
+0

我的东西它没有vb的2008语言,它的C或C++ ,没有帮助,但感谢您的快速响应。 – 2012-02-14 08:22:40

+0

它是C#,它给你的想法,并且很容易转换为VB。 – vulkanino 2012-02-14 08:29:45

+1

ownerdraw是一个属性,不要将您的组合名称设置为ownerdraw! – vulkanino 2012-02-14 13:55:46