Here's one for you!
I have a simple form, where I dynamically draw a series of horizontal
bars (think a column-chart but horizontal :-).
Since the graph depends on dynamic data, I have a method that
determines the number of "columns" (yeah, I should say
horizontal-bars, but I can't help thinking of them as columns) and the
width of each of them (they all have the same height).
Each column is basically described by a RectangleF object, which that
method stores in a class-scoped hashtable.
In any case, my Paint event handler parses through that hashtable and,
for each RectangleF, uses a red SolidBrush to draw it on screen.
So far so good. Now, as I said this is all based on dynamic data.
Thus, when the user does some things, I need to recalculate the
RectangleF objects (since the number and width of the columns may
change). Before doing this, I clear the hastable containing them,
and once I'm done calculating the column widths, I call the form's
Refresh method to have the paint handler re-draw the columns.
When I first tried this, the columns where being left on screen. So,
I realized that I had to clear the screen of the old columns before
re-drawing them with the new data.
How do you do that?
My current work-around is that before clearing the hashtable with the
RectangleF objects, I parse through them and use a SolidBrush (colored
as the form's background color) to "overwrite" each column on screen.
I was wondering if, instead of overwriting the brushes with the
background color, there is a better way to delete/remove/cancel those
(The columns are actually drawn by using the FillRectangle method
of the Graphic object received by the paint handler).
If you have suggestions or idea in regard, I'd be very interested.