代码之家  ›  专栏  ›  技术社区  ›  Mark

GraphicsPath,控件在顶部

  •  0
  • Mark  · 技术社区  · 15 年前

    我有一个自定义的C用户控件,我想在其中绘制一个圆 后面 锚定到控件中心底部的文本框。我画的圆是:

    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);
    }
    

    我已经将文本框添加到了GUI设计器中的控件中。

    当我运行这个程序时,结果是这样的:

    alt text http://i47.tinypic.com/2pyrxbk.jpg

    如何将椭圆保持在文本框后面?

    谢谢, 作记号

    1 回复  |  直到 15 年前
        1
  •  3
  •   Philip Rieck    15 年前

    如果您希望在背景中使用此选项,请在“onpaint background”覆盖中执行此操作,而不是在onpaint中执行此操作。然后,当您想要绘制它时,使椭圆所在的区域无效。