Solved

Changing the color of a drawn rectangle

Posted on 2007-12-04
3
459 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

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:…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now