如何获得 C# Windows 窗体面板绘制边框的正确边界
所以我试图为面板绘制底部边框。我有这样的代码:
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);
}
我还用 DisplayRectangle 和 Bounds 替换了 ClientRectange,它们都产生相同的结果,如图所示。
我试图实现一个底部边框一直穿过桃色背景(用于显示面板的大小)
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);
}
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将 Padding 属性更改为以下内容:
由于您只是想画一条线,所以画一条线:
并确保在调整大小时无效:
Change your Padding property to the following:
Since you are just trying to draw a line, draw a line:
And make sure to invalidate on the resize: