Solved

Changing the color of a drawn rectangle

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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

As game developers, we quickly learn that Artificial Intelligence (AI) doesn’t need to be so tough.  To reference Space Ghost: “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer. (http://www.youtu…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

829 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