2012-02-14 16 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

相關問題