tags:

views:

42

answers:

1

I have a custom C# user-control where I would like to draw a circle behind a textbox anchored to the centered bottom of the control. I'm drawing the circle like:

protected override void OnResize(EventArgs e)
{
   this.gp= new GraphicsPath();
   this.gp.AddEllipse(0,0,width,height); //this is the width and height of the control
   this.Region=new Region(this.gp);
   this.Refresh();
   base.OnResize (e);
}

protected override void OnPaint(PaintEventArgs pe)
{
   Color centerColor = Color.FromArgb(255,255,255,255);
   Color surroundColor = Color.FromArgb(255,255,255,255);
   PathGradientBrush br=new PathGradientBrush(this.gp);
   br.CenterColor=centerColor;
   br.SurroundColors=new Color[]{surroundColor};
   pe.Graphics.FillPath(br,this.gp);
}

I've added the textbox to the control in the GUI designer.

When I run this I end up with something like this:

alt text

How can I keep the ellipse behind the textbox?

Thanks, Mark

+3  A: 

If you want this in the background, do this in the "OnPaintBackground" override rather than in OnPaint. Then, when you want to draw it, invalidate the region the ellipse is in.

Philip Rieck
@Philip, I'm not sure I understand and this may be my problem. The ellipse's region is the control (this.region). Do I need to feed it the region of something else?
Mark
Giving the ellipse it's own region worked!
Mark