[英]C# Button Background Color
我有一个 Windows 表格,我想做一个现代设计。
我只是在按钮样式方面遇到问题,你能帮我吗?
我想在单击按钮时删除或隐藏背景颜色,我设法使用以下代码从鼠标悬停在组件上时删除背景颜色:
FlatAppearance.MouseOverBackColor = System.Drawing.Color.Transparent;
现在我需要删除或隐藏它(灰色背景):
表格图片
我怎么做这个?
谢谢!
我通过多次尝试获得了解决方案。
只需将 FlatAppearance.MouseOverBackColor 和 FlatAppearance.MouseDownBackColor 更改为 Form 或它所附加到的项目的背景颜色。
例子:你有一个带面板的表单,面板的颜色是红色,所以设置属性为红色,或者直接放“Color.Transparent”
buttonName.FlatAppearance.MouseOverBackColor = Color.FromArg(255, 0, 0) // red;
buttonName.FlatAppearance.MouseDownBackColor = Color.Transparent; // same result
因此,如果您有一个扩展按钮 object 的 class,只需编写如下代码:
public class MyButton : Button
{
public MyButton()
{
FlatAppearance.MouseOverBackColor = Color.Transparent; // or Color.[Preference]
FlatAppearance.MouseDownBackColor = Color.Transparent; // or Color.[Preference]
}
// Rest of your code...
}
否则,做一个foreach,如下
foreach (var button in this.Controls.OfType<Button>())
{
button.FlatAppearance.MouseOverBackColor = Color.Transparent; // or Color.[Preference]
button.FlatAppearance.MouseDownBackColor = Color.Transparent; // or Color.[Preference]
}
上面的代码是每个人都能够构建自己的逻辑的示例,如果有疑问我可以帮助你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.