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 combo in vb.net

image combo in vb.net

Scheduled Pinned Locked Moved Visual Basic
csharpdatabasegraphicshelp
2 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 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. :(

    J 1 Reply Last reply
    0
    • D Deepthy P M

      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. :(

      J Offline
      J Offline
      John_Adams
      wrote on last edited by
      #2

      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

      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