tags:

views:

54

answers:

1
+1  Q: 

shape back color

Hi everyone, I have created a User Control using graphic's fill property. It's a circle. It's like a speedometer hence it has many colors and filled using different shapes. I need to have it's empty space to have back color to some thing other than the default color. How to change the back color of the graphic's shape???

+1  A: 

Check out Pens, Brushes and Colors

Graphics g = this.CreateGraphics();
SolidBrush myBrush = new SolidBrush(Color.Red);
g.FillEllipse(myBrush, ClientRectangle);

A more complete example. This will fill the background of the UserControl (based on the size of the user control) to Pink, and create a small circle that is filled with an orange backgroung color.

  protected override void OnPaint(PaintEventArgs e)
  {
     Graphics g = e.Graphics;

     SolidBrush sb = new SolidBrush(Color.Pink);
     g.FillRectangle(sb, e.ClipRectangle);
     sb.Dispose();

     sb = new SolidBrush(Color.Orange);
     g.FillEllipse(sb, 20, 20, 20, 20);
     sb.Dispose();
  }

Is this more what you are looking for?

If you want the background color to be the same as the user control, change this:

SolidBrush sb = new SolidBrush(this.BackColor); //Color.Pink);
SwDevMan81
If i'm not wrong that will draw the shape in RED color. I have drawn the shape in circle it's like a speedometer but I want to set that empty space that is having form color to another color.For example.Graphics g = this.CreateGraphics();SolidBrush myBrush = new SolidBrush(Color.Red);g.FillEllipse(myBrush, ClientRectangle);it creates a rectangle in red shape but inside that rectangle I want some other color. Hope it's clear...
Jankhana
Ok, I updated my example, let me know if thats what you are looking for.
SwDevMan81
Hey that's great I'll try with my code and let you know thanks.
Jankhana
Hey that worked!!!! It's great I needed that only Superb!!! :-)Thank you:-):-)
Jankhana