Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Image ComboBox Control in VB.NET

Image ComboBox Control in VB.NET

Scheduled Pinned Locked Moved Visual Basic
csharpdatabasegraphics
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Deepthy P M
    wrote on last edited by
    #1

    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.

    C 1 Reply Last reply
    0
    • D Deepthy P M

      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.

      C Offline
      C Offline
      CKnig
      wrote on last edited by
      #2

      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?

      D 1 Reply Last reply
      0
      • C CKnig

        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?

        D Offline
        D Offline
        Deepthy P M
        wrote on last edited by
        #3

        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

        C 1 Reply Last reply
        0
        • D Deepthy P M

          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

          C Offline
          C Offline
          CKnig
          wrote on last edited by
          #4

          sorry - did miss the problem with the items-list you need to declare this not as a local variable in the constructor but as a private class field. BTW: if you would say what error message you get we could help you better

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups