按钮在 Windows 7 上具有黑色背景

Posted

技术标签:

【中文标题】按钮在 Windows 7 上具有黑色背景【英文标题】:Button has black background on Windows 7 【发布时间】:2017-01-16 14:48:04 【问题描述】:

我目前正在将针对 WIndows XP 和 Server 2003 的应用程序迁移到 Windows 7(及更高版本)。大多数应用程序运行良好,但某些按钮在 Windows 7 中具有黑色背景。

Windows XP

Windows 7

该应用程序面向 Visual Studio 2005 中的 .NET v2.0(一旦迁移到 Windows 7 完成,我们将迁移到更高版本的 .NET 和 Visual Studio)。可用的属性似乎都没有帮助。以下是我认为可能相关的属性列表(在 XP 和 7 上相同):

BackColor = ActiveCaptionText
BackgroundImage = (none)
TileBackgroundImageLayout = Tile
ForeColor = ControlText
TextImageRelation = Overlay
UseVisualStyleBackColor = False (changing to True doesn't help)

需要做什么才能让按钮看起来像在 Windows XP 上的样子?

【问题讨论】:

您将按钮颜色设置为操作系统定义的 ActiveCaptionText。显然在这台机器上颜色是黑色的。手动将颜色设置为 Color.Grey 或任何 RGB 值。 【参考方案1】:

ActiveCaption 颜色在 SystemColors 类中定义。这些是在操作系统中设置的。

http://msdn.microsoft.com/en-us/library/system.drawing.systemcolors.aspx

活动标题是活动窗口标题栏的背景颜色。

我认为您需要将 BackColor 属性更改为 Control 以使您的表单看起来像您想要的那样:

BackColor = SystemColors.Control;

或任何其他想要的颜色。

【讨论】:

行得通!学习系统颜色的定义可以在 Windows 版本之间更改的好教训。

以上是关于按钮在 Windows 7 上具有黑色背景的主要内容,如果未能解决你的问题,请参考以下文章

华为状态栏怎么变黑色

iOS 9:按钮上的黑色背景,以及某些设备上的性能错误

具有透明背景的 UITableView 具有纯黑色边框

imagemagick - 具有静态黑色背景的动画?

具有透明背景的 QDialog 显示为黑色

在 iOS 6 Flash IPA 中具有黑色背景的 PNG