473,320 Members | 1,817 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 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 997
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: tony kulik | last post by:
This code works fine in ie and opera but not at all in Mozilla. Anybody got a clue as to how to get it right? <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <script...
18
by: Christopher W. Douglas | last post by:
I am writing a VB.NET application in Visual Studio 2003. I have written a method that handles several events, such as closing a form and changing the visible status of a form. I have some code...
8
by: Mark | last post by:
Hi, I'm looking for some ideas on how to build a very simple Event processing framework in my C++ app. Here is a quick background ... I'm building a multithreaded app in C++ (on Linux) that...
4
by: Pekka Karjalainen | last post by:
Hi, this is my first posting here. I also have a question about etiquette. There's a html file associated with my question. I cannot host it indefinitely at the current location. I don't, however,...
6
by: vbMark | last post by:
If I have a control, for example a CheckedListBox, how do I add and event to code, for example that a box has been checked by the user? Thanks
2
by: KC | last post by:
I'm trying to build a simple text editor in part of my app. Right now I'm just testing the basics of the KeyPress event handler. The code is basic...real simple. I'm just testing stuff - Private...
13
by: Charles Law | last post by:
Mr "yEaH rIgHt" posted the following link about a week ago in answer to my question about removing event handlers. > http://www.vbinfozine.com/t_bindevt.shtml Following on from that post, the...
5
by: Richard Grant | last post by:
Hi, I need to "save" in a variable the event handler sub of a control's event, then perform some process, and finally "restore" the originally saved event handler. Example in pseudo-code: 1)...
17
by: dan_williams | last post by:
I have the following test web page:- <html> <head><title>Test</title> <script language="Javascript"> <!-- function fnTR() { alert("TR"); }
5
by: Steve | last post by:
In VB6 I have a screen the has a text box and a datagrid If I click the datagrid, the 1st event is to validate the textbox and then the 2nd event is a datagrid mousedown event. If a get an error...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.