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. C#
  4. How to place images in the ListBox items?

How to place images in the ListBox items?

Scheduled Pinned Locked Moved C#
helptutorialquestion
3 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.
  • S Offline
    S Offline
    Saravanan_article
    wrote on last edited by
    #1

    Hi friends, I am developing windows based application.. I am using ListBox in my application.. I dont know how to insert the images in the listbox control items.. I want to display seperate images for the items in the listbox.. Any help or suggesstion is helpful to do that.. Thanks in advance Regards, SAravanan

    L 1 Reply Last reply
    0
    • S Saravanan_article

      Hi friends, I am developing windows based application.. I am using ListBox in my application.. I dont know how to insert the images in the listbox control items.. I want to display seperate images for the items in the listbox.. Any help or suggesstion is helpful to do that.. Thanks in advance Regards, SAravanan

      L Offline
      L Offline
      Libor Tinka
      wrote on last edited by
      #2

      First, create a class that contains image, something like this: public class ListBoxItem { public Image img; public string text; public override ToString() { return text; } } Then you need to create owner-drawn ListBox (which iherits a ListBox class). First, set DrawMode property to OwnerDrawFixed or OwnerDrawVariable (i like the second one). Then you need to override OnMeasureItem and OnDrawItem methods. Make sure, you've set right size for the item in measuring method so you can draw it properly later. If you want to use images with alpha channel, use ImageList.Draw which can do the job.

      S 1 Reply Last reply
      0
      • L Libor Tinka

        First, create a class that contains image, something like this: public class ListBoxItem { public Image img; public string text; public override ToString() { return text; } } Then you need to create owner-drawn ListBox (which iherits a ListBox class). First, set DrawMode property to OwnerDrawFixed or OwnerDrawVariable (i like the second one). Then you need to override OnMeasureItem and OnDrawItem methods. Make sure, you've set right size for the item in measuring method so you can draw it properly later. If you want to use images with alpha channel, use ImageList.Draw which can do the job.

        S Offline
        S Offline
        Saravanan_article
        wrote on last edited by
        #3

        Will u please post the code.. because i am a newbiew to C#.Net Thanks for ur help Regards, Saravanan

        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