WM_ERASEBKGND - which item?

  • Thread starter Thread starter Bob Dankert
  • Start date Start date
B

Bob Dankert

I am capturing the WM_ERASEBKGND in my ownerdraw listbox in WndProc to
reduce flicker (if it doesnt erase the background, it doesnt flicker).
However, after the last item in the listbox, there is a spot which should be
filled with white (about half the size of an item) which is instead willed
with half of my last drawn item.

Is there any way to tell in WndProc when WM_ERASEBKGND is called which item
in the listbox it is trying to erase? I want it to not fire on all but the
very end of the listbox.

Thanks,

Bob Dankert
 
Alright, I figured out an easy workaround for this. In the DrawItem for the
listbox, I just added the code:

if (e.Index == this.Items.Count - 1)

if (this.Bounds.Height - (e.Bounds.Y+e.Bounds.Height) > 0)

e.Graphics.FillRectangle(Brushes.White,e.Bounds.X,e.Bounds.Y+e.Bounds.Height
,e.Bounds.Width,this.Bounds.Height - (e.Bounds.Y+e.Bounds.Height));

This will erase everything within the listbox that is below the last item in
the listbox, and I just cancel all WM_ERASEBKGND events to eliminate all
flicker.



Thanks,

Bob Dankert
 
Back
Top