Image ComboBox Control in VB.NET
-
I want to display color image with corresponding color name in combo box.I got to display color in combobox not corresponding color name. The code is 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 :( How i display corresponding color name in that combo box.
-
I want to display color image with corresponding color name in combo box.I got to display color in combobox not corresponding color name. The code is 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 :( How i display corresponding color name in that combo box.
well - you managed to show the images .. the text is much simpler. Just add the following line just after your e.Graphics.DrawImage line:
e.Graphics.DrawString(items(e.Index),me.Font,Brushes.Black,e.Bounds)
(didn't test it so there might be a typo but I guess you get the idea) BTW: you should but handle the case where the current cell is focused - normaly you use the e.DrawFocusRectangle() but this is not the way here - maybe just draw a shading (with an almost transparent brush) over your picture? -
well - you managed to show the images .. the text is much simpler. Just add the following line just after your e.Graphics.DrawImage line:
e.Graphics.DrawString(items(e.Index),me.Font,Brushes.Black,e.Bounds)
(didn't test it so there might be a typo but I guess you get the idea) BTW: you should but handle the case where the current cell is focused - normaly you use the e.DrawFocusRectangle() but this is not the way here - maybe just draw a shading (with an almost transparent brush) over your picture?I cant get .In Imagelist i used bmp image to set that color.When i typed the code that u given.Its not worked.Pls help me
-
I cant get .In Imagelist i used bmp image to set that color.When i typed the code that u given.Its not worked.Pls help me