Event Handler Basics

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • JB

    #1

    Event Handler Basics

    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, DrawItemEventAr gs e)
    {
    Bitmap img = new Bitmap("cross.g if");
    e.DrawBackgroun d();
    e.DrawFocusRect angle();
    Image i = img;
    e.Graphics.Draw Image(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?
  • Peter Duniho

    #2
    Re: Event Handler Basics

    On Thu, 12 Jun 2008 08:01:29 -0700, JB <jamesb457@gmai l.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 DrawItemEventAr gs 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

    Comment

    Working...