如何更改表单边框颜色c#?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1445472/
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 form border color c#?
提问by don
I would like to change window form border color (the border with the form title). The example I found in codeplexis too much and confusing. Can any help me on something simpler?
我想更改窗口窗体边框颜色(带有窗体标题的边框)。我在codeplex 中找到的示例太多且令人困惑。任何人都可以帮助我做一些更简单的事情吗?
回答by Reed Copsey
Unfortunately, since the form border is drawn by the Operating System, this is a complicated task. There is no real way around that.
不幸的是,由于表单边框是由操作系统绘制的,因此这是一项复杂的任务。没有真正的解决办法。
Do NOT click the ProjectDistributor link on the CodePlex page below
请勿单击下方 CodePlex 页面上的 ProjectDistributor 链接
The CodePlex Project for Drawing Custom Bordersmakes this very easy, though. Just build the form using SkinnedForm from that project instead of a standard Form, and it should work - you really don't need to do anything different in your code.
不过,用于绘制自定义边框的CodePlex 项目使这变得非常容易。只需使用该项目中的 SkinnedForm 而不是标准表单来构建表单,它应该可以工作 - 您真的不需要在代码中做任何不同的事情。
回答by Baqar Hassan
if (colorDialog1.ShowDialog() == DialogResult.OK)
{
string color = Convert.ToString(colorDialog1.Color);
MessageBox.Show("You change the color " + color);
this.BackColor = colorDialog1.Color; // BackColor is only accessible for this form
}
回答by LunaDev
Below "ForeColor" their should be a setting called "FormBorderStyle" You can edit it with that in VisualStudio 2015. Or you can go in control panel path should be something like this "Control Panel\Appearance and Personalization\Personalization" their will be a second setting called "Color" can change that to be what color you want it will change the color of the boarder in all of the programs to the color you set.
在“ForeColor”下方,它们应该是一个名为“FormBorderStyle”的设置,您可以在 VisualStudio 2015 中使用该设置进行编辑。或者您可以进入控制面板路径应该是这样的“控制面板\外观和个性化\个性化”,它们将是一个称为“颜色”的第二个设置可以将其更改为您想要的颜色,它将所有程序中的边界颜色更改为您设置的颜色。
回答by Essam Mohamed Fahmi
Just follow these steps :
只需按照以下步骤操作:
- Set
FormBorderStyle
to None - Cover the form with a panel and leave some space for border
- Set the color you want for the border as the form back color
- 设置
FormBorderStyle
为无 - 用面板覆盖表单并为边框留出一些空间
- 将您想要的边框颜色设置为表单背景颜色
Now, the panel serves as the main container and you can change the background as you want and the form serves as the border !
现在,面板充当主容器,您可以根据需要更改背景,表单充当边框!
The Final Result :
最终结果:
回答by Hacki
Override it with:
覆盖它:
protected override void OnPaint(PaintEventArgs e)
{
ControlPaint.DrawBorder(e.Graphics, ClientRectangle, Color.[your_color], ButtonBorderStyle.Solid);
}