开发者

How to get proper bounds for a C# Windows Forms Panel to draw a border

So I am trying to draw a bottom border for a panel. I have this code:

private void pnl_Paint(object sender, PaintEventArgs e)
{
    ControlPaint.DrawBorder(e.Graphics, ((Panel)sender).ClientRectangle, Color.Transparent, 0, ButtonBorderStyle.None, Color.Transparent, 0, ButtonBorderStyle.None, Color.Transparent, 0, ButtonBorderStyle.None, SystemColors.ControlDarkDark, 1, ButtonBorderStyle.Solid);
}开发者_如何学Go

I have also replaced ClientRectange with DisplayRectangle and Bounds, and all of them produce the same result, the one in the picture.

I am trying to achieve a bottom border going all the way across the peach background (used to display the size of the panel)

How to get proper bounds for a C# Windows Forms Panel to draw a border


Change your Padding property to the following:

pnl.Padding = new Padding(0, 0, 0, 1);

Since you are just trying to draw a line, draw a line:

private void pnl_Paint(object sender, PaintEventArgs e) {
  e.Graphics.DrawLine(Pens.Black, new Point(0, pnl.ClientSize.Height - 1), new Point(pnl.ClientSize.Width, pnl.ClientSize.Height - 1));
}

And make sure to invalidate on the resize:

private void pnl_Resize(object sender, EventArgs e) {
  pnl.Invalidate();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜