Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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,
Reply With Quote
  #2 (permalink)  
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
Reply With Quote
  #3 (permalink)  
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.

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

All times are GMT -4. The time now is 08:30 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.