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:
How can I keep the ellipse behind the textbox?
Thanks, Mark
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.
精彩评论