Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
| Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old June 20th, 2003, 07:43 AM
Authorized User
Join Date: Jun 2003
Location: Gainesville, FL, USA.
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default Un-brushing

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.

Thank you,
Old June 30th, 2003, 05:06 AM
Friend of Wrox
Join Date: Jun 2003
Location: , , .
Posts: 453
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Ankur_Verma Send a message via MSN to Ankur_Verma

Hi Olorin

Since there is no such thing as InvalidateRect(VC++) in
C#, what you are doing looks to me the only way-round to
this problem unless ofcourse to go for the PInvoke
technique to map InvalidateRect in C# and use It.

Write back if there is anything else you wanna ask me.

Ankur Verma
.Net and C++ Specialist
Wiley Tech Support
Old July 2nd, 2003, 03:02 PM
Authorized User
Join Date: Jun 2003
Location: Gainesville, FL, USA.
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts

thanks for the info.
Sorry if I didn't reply earlier, but I've been off line for a while :-)

Anyway, I appreciate the reply, and I'll keep on looking for alternatives.
I'll post here if I find any better way to invalidate those rectangles.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.