Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Changing the color of a drawn rectangle

Posted on 2007-12-04
3
Medium Priority
?
467 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 2000 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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

Artificial Intelligence comes in many forms, and for game developers, Path-Finding is an important ability for making an NPC (Non-Playable Character) maneuver through terrain.  A* is a particularly easy way to approach it.  I’ll start with the algor…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

618 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