0
我需要你一段時間來幫助我,我正在創建一個項目,我需要在組合框項目前面設置像32X32或16X16像素的小圖片。 在此先感謝。如何將小圖片放在組合框項目前面?
我需要你一段時間來幫助我,我正在創建一個項目,我需要在組合框項目前面設置像32X32或16X16像素的小圖片。 在此先感謝。如何將小圖片放在組合框項目前面?
此鏈接可以幫助你: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
我的東西它沒有vb的2008語言,它的C或C++ ,沒有幫助,但感謝您的快速響應。 – 2012-02-14 08:22:40
它是C#,它給你的想法,並且很容易轉換爲VB。 – vulkanino 2012-02-14 08:29:45
ownerdraw是一個屬性,不要將您的組合名稱設置爲ownerdraw! – vulkanino 2012-02-14 13:55:46