wpf 如何更改面板的边框样式?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22192218/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to change the BorderStyle for a Panel?
提问by GibboK
I have a panel System.Windows.Forms.Panel
我有一个面板 System.Windows.Forms.Panel
with property
有财产
BorderStyle="FixedSingle"
It render with a gray color border.
它以灰色边框呈现。
I need:
我需要:
to be able to set the color and the thickness if possible for the border.
I am interested to know if it also possible hide completely the border.
如果可能,能够为边框设置颜色和粗细。
我很想知道是否也可以完全隐藏边界。
Any idea how to solve this?
知道如何解决这个问题吗?
Code for my control:
我的控制代码:
OptimizedPanel : Panel
<WindowsFormsHost Name="WinFormsHost">
<wh:OptimizedPanel x:Name="RenderingPanel"
BorderStyle="None" />
</WindowsFormsHost>
采纳答案by lc.
If you want to change the color or thickness, I believe you have to set BorderStyle.Noneand draw the border yourself.
如果要更改颜色或粗细,我相信您必须自己设置BorderStyle.None和绘制边框。
If you want to hide the border, you can use the value BorderStyle.None, which also happens to be the default.
如果你想隐藏边框,你可以使用 value BorderStyle.None,这也恰好是默认值。
See also: http://msdn.microsoft.com/en-us/library/system.windows.forms.panel.borderstyle%28v=vs.110%29.aspx
另请参阅:http: //msdn.microsoft.com/en-us/library/system.windows.forms.panel.borderstyle%28v=vs.110%29.aspx
回答by BRAHIM Kamel
I am interested to know if it also possible hide completely the border.
我很想知道是否也可以完全隐藏边界。
Yes, just try this:
是的,试试这个:
panel1.BorderStyle = BorderStyle.None;
回答by SimonPJ
You can create an extension class of panel and override the paint method. Then you can draw whatever border you like when the panel is repainted.
您可以创建面板的扩展类并覆盖paint方法。然后您可以在重新粉刷面板时绘制您喜欢的任何边框。
As far as I am aware there is no method for border colours included with panel by default.
据我所知,默认情况下面板中没有包含边框颜色的方法。
As for hiding the border simply BorderStyle.None
至于简单的隐藏边框 BorderStyle.None
回答by Shell
Windows.Forms.Form.Panel control does not support border color. So, you cannot set border color directly. But you can draw your own border using graphics object.
Windows.Forms.Form.Panel 控件不支持边框颜色。因此,您不能直接设置边框颜色。但是您可以使用图形对象绘制自己的边框。
private void pnlPanel_Paint(object sender, PaintEventArgs e)
{
Rectangle r = new Rectangle(0, 0, this.ClientRectangle.Width - 1, this.ClientRectangle.Height - 1);
Pen p = new Pen(Color.Blue, 2);
e.Graphics.DrawRectangle(p, r);
}
Dont forget to set BorderStyleproperty to None
不要忘记将BorderStyle属性设置为None
pnlPanel.BorderStyle = BorderStyle.None;

