471,342 Members | 1,858 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,342 software developers and data experts.

Event Handler Basics

JB
I have a listbox of which I have overrode the 'DrawItem' event to
display an image.

So I have a function as follows:

private void DrawItemHandler(object sender, DrawItemEventArgs e)
{
Bitmap img = new Bitmap("cross.gif");
e.DrawBackground();
e.DrawFocusRectangle();
Image i = img;
e.Graphics.DrawImage(i, new Point(e.Bounds.X,
e.Bounds.Y));
}

-
What I want is a button which will scan all items in the listbox,
check to see whether the item exists in the database, and then change
the image accordingly ("tick.gif").

-
What is the best method of doing this?

I can check which the image should be easily enough, but i cant pass a
value to the DrawItemHandler. Or can I?
Jun 27 '08 #1
1 952
On Thu, 12 Jun 2008 08:01:29 -0700, JB <ja*******@gmail.comwrote:
[...]
What I want is a button which will scan all items in the listbox,
check to see whether the item exists in the database, and then change
the image accordingly ("tick.gif").

-
What is the best method of doing this?

I can check which the image should be easily enough, but i cant pass a
value to the DrawItemHandler. Or can I?
I'm not really sure what you're asking. The DrawItemEventArgs class
provides the information as to _which_ item is being drawn. You should be
able to use that to decide which bitmap to draw.

By the way, as far as the code you posted goes, at a minimum you have a
bug in that you don't dispose the Bitmap object when you're done with it.
In practice, it would be better if you just allocate the Bitmap object
once and store it somewhere for reuse. That way you're not creating and
disposing the same object over and over for each item you draw.

Pete
Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by tony kulik | last post: by
18 posts views Thread by Christopher W. Douglas | last post: by
8 posts views Thread by Mark | last post: by
4 posts views Thread by Pekka Karjalainen | last post: by
6 posts views Thread by vbMark | last post: by
2 posts views Thread by KC | last post: by
13 posts views Thread by Charles Law | last post: by
5 posts views Thread by Richard Grant | last post: by
17 posts views Thread by dan_williams | last post: by
5 posts views Thread by Steve | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.