image combo in vb.net
-
I want to display color with corresponding color name in combo box.In my program i used for this image list.In that i stored bmp images.But i want to display color name also.How i do that .My code is Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim items(Me.ImageList1.Images.Count - 1) As String For i As Int32 = 0 To Me.ImageList1.Images.Count - 1 items(i) = "Item " & i.ToString Next Me.ComboBox1.Items.AddRange(items) Me.ComboBox1.DropDownStyle = ComboBoxStyle.DropDownList Me.ComboBox1.DrawMode = DrawMode.OwnerDrawVariable Me.ComboBox1.ItemHeight = Me.ImageList1.ImageSize.Height Me.ComboBox1.Width = Me.ImageList1.ImageSize.Width + 18 Me.ComboBox1.MaxDropDownItems = Me.ImageList1.Images.Count End Sub Private Sub ComboBox1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles ComboBox1.DrawItem If e.Index <> -1 Then e.Graphics.DrawImage(Me.ImageList1.Images(e.Index), e.Bounds.Left, e.Bounds.Top) End If End Sub Private Sub ComboBox1_MeasureItem(ByVal sender As Object, ByVal e As System.Windows.Forms.MeasureItemEventArgs) Handles ComboBox1.MeasureItem e.ItemHeight = Me.ImageList1.ImageSize.Height e.ItemWidth = Me.ImageList1.ImageSize.Width End Sub Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged Select Case (ComboBox1.SelectedIndex) Case 0 TextBox1.ForeColor = Color.Red Exit Select Case 1 TextBox1.ForeColor = Color.Yellow Exit Select End Select End Sub End Class When i add the following code in combobox1_Drawitem e.Graphics.DrawString(items(e.Index), Me.Font, Brushes.Black, e.Bounds) It is not working bcs when i set a color name in items(e.index))it is common to every image.How can i solve this problem. :(
-
I want to display color with corresponding color name in combo box.In my program i used for this image list.In that i stored bmp images.But i want to display color name also.How i do that .My code is Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim items(Me.ImageList1.Images.Count - 1) As String For i As Int32 = 0 To Me.ImageList1.Images.Count - 1 items(i) = "Item " & i.ToString Next Me.ComboBox1.Items.AddRange(items) Me.ComboBox1.DropDownStyle = ComboBoxStyle.DropDownList Me.ComboBox1.DrawMode = DrawMode.OwnerDrawVariable Me.ComboBox1.ItemHeight = Me.ImageList1.ImageSize.Height Me.ComboBox1.Width = Me.ImageList1.ImageSize.Width + 18 Me.ComboBox1.MaxDropDownItems = Me.ImageList1.Images.Count End Sub Private Sub ComboBox1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles ComboBox1.DrawItem If e.Index <> -1 Then e.Graphics.DrawImage(Me.ImageList1.Images(e.Index), e.Bounds.Left, e.Bounds.Top) End If End Sub Private Sub ComboBox1_MeasureItem(ByVal sender As Object, ByVal e As System.Windows.Forms.MeasureItemEventArgs) Handles ComboBox1.MeasureItem e.ItemHeight = Me.ImageList1.ImageSize.Height e.ItemWidth = Me.ImageList1.ImageSize.Width End Sub Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged Select Case (ComboBox1.SelectedIndex) Case 0 TextBox1.ForeColor = Color.Red Exit Select Case 1 TextBox1.ForeColor = Color.Yellow Exit Select End Select End Sub End Class When i add the following code in combobox1_Drawitem e.Graphics.DrawString(items(e.Index), Me.Font, Brushes.Black, e.Bounds) It is not working bcs when i set a color name in items(e.index))it is common to every image.How can i solve this problem. :(
Hi There, In reference to your query I would suggest you to read the following article and look at the code snippet mentioned in the article. Below is the link of the article. http://www.codeproject.com/KB/combobox/ImageCombo_NET.aspx?df=100&forumid=31201&exp=0&select=964166[^] I hope this would be helpful.
Regards, John Adams ComponentOne LLC