Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在控件上仅绘制选定的边框_C#_.net_Winforms - Fatal编程技术网

C# 如何在控件上仅绘制选定的边框

C# 如何在控件上仅绘制选定的边框,c#,.net,winforms,C#,.net,Winforms,我正在构建一个自定义控件,我需要它只绘制顶部边框。怎样才能做到呢 编辑:目前我正在使用以下代码: protected override void OnPaint(PaintEventArgs e) { if (!this.DesignMode) { Rectangle bounds = this.ClientRectangle; GraphicsPath topEdge = new GraphicsPath(); topEdge.S

我正在构建一个自定义控件,我需要它只绘制顶部边框。怎样才能做到呢

编辑:目前我正在使用以下代码:

protected override void OnPaint(PaintEventArgs e)
{
    if (!this.DesignMode)
    {
        Rectangle bounds = this.ClientRectangle;
        GraphicsPath topEdge = new GraphicsPath();
        topEdge.StartFigure();
        topEdge.AddLine(bounds.X, bounds.Y, bounds.X + bounds.Width, bounds.Y);
        topEdge.CloseFigure();
        e.Graphics.DrawPath(new Pen(SystemColors.ActiveBorder, 1), topEdge);
    }
    base.OnPaint(e);
}
当我的自定义控件中没有嵌套控件时,这种方法非常有效。一旦我开始添加控件,它们似乎就超出了边界线。

使用。本文简介:以下内容在控件周围添加了边框:

protected override void OnPaint(PaintEventArgs e)
{
  base.OnPaint(e);
  ControlPaint.DrawBorder(e.Graphics, ClientRectangle,
                            Color.Black, BORDER_SIZE, ButtonBorderStyle.Inset,
                            Color.Black, BORDER_SIZE, ButtonBorderStyle.Inset,
                            Color.Black, BORDER_SIZE, ButtonBorderStyle.Inset,
                            Color.Black, BORDER_SIZE, ButtonBorderStyle.Inset);
} 

我可以划一条线吗guess@sa_ddam213:谢谢你的评论。这就是我正在做的。但是这些线被我的自定义控件中的其他控件过度绘制。所以我需要一个万无一失的方法。