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. Help with images in listview

Help with images in listview

Scheduled Pinned Locked Moved C#
graphicshelpalgorithms
3 Posts 3 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.
  • A Offline
    A Offline
    anu81
    wrote on last edited by
    #1

    hi all, I have a listview in which i am trying to display thumbnail images along with text like the windows explorer. I am able to display the thumbnail view with lots of help from members here. and i tried of sorting out the flickering problem in listview. but when i try to drag the vertical scrollbar down or up rather, the images are not aligned properly and it sort of is overwritten over one another. here is the code i used for drawing the item(having set the owner draw property true).this is just a sample code with the controls having their default names. private void listView1_DrawItem(object sender, System.Windows.Forms.DrawListViewItemEventArgs e) { if (imageList1.Images.Count > 0) { // Draw the item text for views other than the Details view. if (listView1.View != View.Details) { //Image newimage = new Bitmap(imageList1.Images[e.ItemIndex]); Image newimage = new Bitmap(imageList1.Images[0]); left = e.Bounds.Left + 5; top = e.Bounds.Y + this.Height / 7; width = newimage.Width + 5; height = newimage.Height - 25; textbrush = new SolidBrush(Color.FromArgb(255, 236, 233, 216)); Rectangle text_rect = new Rectangle(left, top, width, height); text = e.Item.Text; DrawRoundedRectangle(e.Graphics, new Pen(textbrush), Color.White, text_rect, new Size(8, 8), newimage, text); left = left + 20; top = top + 130; text_rect = new Rectangle(left - 5, top - 25, width - 30, 20); DrawRoundedRectangle(e.Graphics, new Pen(new SolidBrush(Color.White)), Color.White, text_rect, new Size(1, 1), null, text); listView1.EnsureVisible(e.ItemIndex); } } } public void DrawRoundedRectangle(Graphics g, Pen p, Color backColor, Rectangle rc, Size size, Image img, string text) { Point[] points = new Point[8]; //prepare points for poligon points[0].X = rc.Left + size.Width / 2; points[0].Y = rc.Top + 1; points[1].X = rc.Right - size.Width / 2; points[1].Y = rc.Top + 1; points[2].X = rc.Right; points[2].Y = rc.Top + size.Height / 2;

    J L 2 Replies Last reply
    0
    • A anu81

      hi all, I have a listview in which i am trying to display thumbnail images along with text like the windows explorer. I am able to display the thumbnail view with lots of help from members here. and i tried of sorting out the flickering problem in listview. but when i try to drag the vertical scrollbar down or up rather, the images are not aligned properly and it sort of is overwritten over one another. here is the code i used for drawing the item(having set the owner draw property true).this is just a sample code with the controls having their default names. private void listView1_DrawItem(object sender, System.Windows.Forms.DrawListViewItemEventArgs e) { if (imageList1.Images.Count > 0) { // Draw the item text for views other than the Details view. if (listView1.View != View.Details) { //Image newimage = new Bitmap(imageList1.Images[e.ItemIndex]); Image newimage = new Bitmap(imageList1.Images[0]); left = e.Bounds.Left + 5; top = e.Bounds.Y + this.Height / 7; width = newimage.Width + 5; height = newimage.Height - 25; textbrush = new SolidBrush(Color.FromArgb(255, 236, 233, 216)); Rectangle text_rect = new Rectangle(left, top, width, height); text = e.Item.Text; DrawRoundedRectangle(e.Graphics, new Pen(textbrush), Color.White, text_rect, new Size(8, 8), newimage, text); left = left + 20; top = top + 130; text_rect = new Rectangle(left - 5, top - 25, width - 30, 20); DrawRoundedRectangle(e.Graphics, new Pen(new SolidBrush(Color.White)), Color.White, text_rect, new Size(1, 1), null, text); listView1.EnsureVisible(e.ItemIndex); } } } public void DrawRoundedRectangle(Graphics g, Pen p, Color backColor, Rectangle rc, Size size, Image img, string text) { Point[] points = new Point[8]; //prepare points for poligon points[0].X = rc.Left + size.Width / 2; points[0].Y = rc.Top + 1; points[1].X = rc.Right - size.Width / 2; points[1].Y = rc.Top + 1; points[2].X = rc.Right; points[2].Y = rc.Top + size.Height / 2;

      J Offline
      J Offline
      Justin Perez
      wrote on last edited by
      #2

      anu81 wrote:

      but when i try to drag the vertical scrollbar down or up rather, the images are not aligned properly and it sort of is overwritten over one another.

      I didn't really look much thru the code, but here's what I suggest you try doing: In the listview events, find something for vertical scroll. When the event has finished, re-draw your images using the new coordinates of your object.

      I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")

      1 Reply Last reply
      0
      • A anu81

        hi all, I have a listview in which i am trying to display thumbnail images along with text like the windows explorer. I am able to display the thumbnail view with lots of help from members here. and i tried of sorting out the flickering problem in listview. but when i try to drag the vertical scrollbar down or up rather, the images are not aligned properly and it sort of is overwritten over one another. here is the code i used for drawing the item(having set the owner draw property true).this is just a sample code with the controls having their default names. private void listView1_DrawItem(object sender, System.Windows.Forms.DrawListViewItemEventArgs e) { if (imageList1.Images.Count > 0) { // Draw the item text for views other than the Details view. if (listView1.View != View.Details) { //Image newimage = new Bitmap(imageList1.Images[e.ItemIndex]); Image newimage = new Bitmap(imageList1.Images[0]); left = e.Bounds.Left + 5; top = e.Bounds.Y + this.Height / 7; width = newimage.Width + 5; height = newimage.Height - 25; textbrush = new SolidBrush(Color.FromArgb(255, 236, 233, 216)); Rectangle text_rect = new Rectangle(left, top, width, height); text = e.Item.Text; DrawRoundedRectangle(e.Graphics, new Pen(textbrush), Color.White, text_rect, new Size(8, 8), newimage, text); left = left + 20; top = top + 130; text_rect = new Rectangle(left - 5, top - 25, width - 30, 20); DrawRoundedRectangle(e.Graphics, new Pen(new SolidBrush(Color.White)), Color.White, text_rect, new Size(1, 1), null, text); listView1.EnsureVisible(e.ItemIndex); } } } public void DrawRoundedRectangle(Graphics g, Pen p, Color backColor, Rectangle rc, Size size, Image img, string text) { Point[] points = new Point[8]; //prepare points for poligon points[0].X = rc.Left + size.Width / 2; points[0].Y = rc.Top + 1; points[1].X = rc.Right - size.Width / 2; points[1].Y = rc.Top + 1; points[2].X = rc.Right; points[2].Y = rc.Top + size.Height / 2;

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        anu81 wrote:

        Image newimage = new Bitmap(imageList1.Images[0]);

        I assume imageListI.Images contains images, so why do you create a new Image here? Can't you do just Image newimage = imageList1.Images[e.ItemIndex];? :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        this months tips: - use PRE tags to preserve formatting when showing multi-line code snippets - before you ask a question here, search CodeProject, then Google


        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