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:谢谢你的评论。这就是我正在做的。但是这些线被我的自定义控件中的其他控件过度绘制。所以我需要一个万无一失的方法。