By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,579 Members | 1,618 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,579 IT Pros & Developers. It's quick & easy.

Ownerdrawn ListBox produces flawed graphics

P: n/a

I'm trying to make an ownerdrawn ListBox that can display a custom graphic
and 2 lines of text per item.

I have tried to set the following properties on a standard ListBox control:

DrawMode = OwnerDrawFixed
ItemHeight = 32

In the DrawItem Event for the ListBox, I have placed the following code for
testing purposes:

Private Sub ListBox1_DrawItem(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.DrawItemEventArgs) Handles ListBox1.DrawItem
e.Graphics.FillRectangle(System.Drawing.Brushes.Po wderBlue, e.Bounds)
e.Graphics.DrawRectangle(System.Drawing.Pens.DarkB lue, e.Bounds)

End Sub

This code should draw a powder blue background, with a dark blue outline for
each item in the ListBox (I know the outline will lack the right and bottom
borders due to some unfortunate usage of the e.Bounds rectangle, this is for
demonstration purposes only :o)

At first all Items draw correctly, but after selecting another item, or
resizing the control or scrolling, the backgrounds (powder blue) all still
draw, and text (omitted in example code) would also draw correctly, but the
dark blue outline rectangles get clipped randomly it seems...

Am I doing something wrong? I doubt it, since I have seen examples by
Microsoft demonstrating how to create an ownerdrawn ListBox with this
problem occurring as well.

Does anyone know how to work around this issue, or have any idea what is
causing this?


Danny van Kasteel
Nov 20 '05 #1
Share this Question
Share on Google+
1 Reply

P: n/a
Ah! Apparently, updating one's graphics drivers does the trick :o)
Nov 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.