Hi everyone,
I have been writing a windows app in C# which requires images in a listbox. I have managed to do that with the help of User Draw mode. However, the images appear blurred in the list box. I have tried adjusting the size of the rectangle they are drawn in but the problem persists. Please let me know how this problem can be solved.
Thanks a lot
Anjali
Anjali RPosted Jul 18, 2008, 9:59 PM
Hi Niradhip,
Thank you for your reply and the link. The method I have used in my program is similar. I am attaching the code below. Everything seems to work fine except the images are horribly blurred. I am loading the images into an imagelist at designtime and then using them from there to draw them onto the listbox. My code is as below.
Thanks in advance
Anjali
namespace listboxWithImages{
public partial class Form1 : Form
{
static int delta = 5;
public Form1()
{
InitializeComponent();
} private void listBox1_DrawItem(object sender, DrawItemEventArgs e)
{
Image image1;
image1 = imageList1.Images[e.Index];
Rectangle rc = new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width - delta, e.Bounds.Height - delta); // Draw the rectangle
e.Graphics.DrawRectangle(new Pen(new SolidBrush(Color.Black), 2), rc);
e.Graphics.FillRectangle(new SolidBrush(Color.White), rc);
e.Graphics.DrawRectangle(new Pen(new SolidBrush(Color.Black), 2), rc);
e.Graphics.DrawImage(image1, rc);
e.DrawFocusRectangle();
} private void Form1_Load(object sender, EventArgs e)
{
this.Refresh();
listBox1.DrawMode = DrawMode.OwnerDrawFixed;
listBox1.ItemHeight = 60;
listBox1.Items.Add("image1");
listBox1.Items.Add("image2");
listBox1.Items.Add("image3");
listBox1.Items.Add("image4");
listBox1.Items.Add("image5");
listBox1.Items.Add("image6");
listBox1.Items.Add("image7");
}
}
}
Niradhip ChakrabortyPosted Jul 18, 2008, 1:00 PM
Hi Anjali,
Welcome to c-sharpcorner. Unless we review your code, It’s bit difficult to give any solution. You can post your code and all the necessary information like how you are fetching the images path(from database or from somewhere else..).With all the information, it will create a good chance to answer the question by someone in the forum. Meanwhile you can go ahead and download the code from the following URL. It will help you to execute your tusk in style.
http://www.devhood.com/tools/tool_details.aspx?tool_id=257