Help with images in listview
-
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;
-
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;
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")
-
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;
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