C# - 如何检索窗口的背景颜色
我在这个论坛中进行了搜索,但没有找到任何可以帮助我完成以下任务的内容。如果可能的话请帮忙。谢谢。
我已将窗口的背景设置为黑色(或我喜欢的任何其他颜色)。作为应用程序完成的计算的一部分,我在该窗口上以颜色绘制不同的区域。区域的颜色是动态的,我想在颜色更改之前找到并存储该区域的起始颜色,以便我可以返回到该基色。例如,如果起始背景颜色是黑色,并且应用程序将颜色更改为绿色,我想在需要时将颜色返回到基色黑色,而不必记住基色是黑色。
我尝试使用
private Color backgroundColor = (Color)System.Drawing.SystemColors.Window;
,然后
BackColor = backgroundColor;
这确实有效,但颜色回到白色而不是我在偏好中指定的黑色。
有人可以建议一个解决方案吗?非常感谢您提供的任何帮助。
I have searched in this forum and I have not found anything that would help me with the following. Please help if possible. Thank you.
I have set the background of a window to black (or any other color I like). As part of the calculations done by the app, I plot different regions in color on that window. The color of the regions is dynamic and I would like to find and store the starting color of the region before the color change so that I can return to that base color. For example, if the starting background color is black, and the app changes the color to green, I would like to return the color back to the base color black when needed without having to remember that the base color was black.
I tried using
private Color backgroundColor = (Color)System.Drawing.SystemColors.Window;
and then later on
BackColor = backgroundColor;
This does work but the color goes back to white rather than the black I had specified in my preferences.
Can anyone please suggest a solution? Thank you very much for any help you may be bale to provide.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,SystemColors.Window 默认情况下是白色的。你可能想要这个:
Yes, SystemColors.Window is white by default. You probably want this: