Solved

Changing the color of a drawn rectangle

Posted on 2007-12-04
3
460 Views
Last Modified: 2013-12-16
Hi Experts,

   I have a user control (C# 2005 w/ .NET FW 2.0), which has a picture box. When the user control gets created for the first time, I draw a rectangle on top of it using the picture box' Graphics object and the FillRectangle (Brush, RectangleF) function (using a SolidBrush).  I have a public method, that's supposed to allow the user to change the rectangle's color.  My question is: How do I change the color of that existing rectangle? I tried saving the RectangleF object and just calling the FillRectangle function on it a second time using a different Brush color, but that returns a "Parameter is not valid" error.

Any help would be greatly appreciated.

Thanks,
axnst2
0
Comment
Question by:axnst2
  • 2
3 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 20403610
You could use a private field value to store the selected color, and then call the Invalidate method for the PictureBox to fire the Paint event, and fill the rectangle in the Paint event handler, using the stored color for the SolidBrush.

Bob
0
 

Author Comment

by:axnst2
ID: 20404782
Thanks Bob,

   That was it...

~axnst2
0
 

Author Closing Comment

by:axnst2
ID: 31412595
Good Job!!!!
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question