按钮的背景颜色 [英] Button background colour
问题描述
我需要使用C#code(Visual Studio 2008中)更改背景按钮
颜色。
I need to change the background
colour of a button using C# code (Visual Studio 2008).
我看到一些人建议指令列入:使用System.Windows.Media
; - 我尝试过了,它触发此错误:Windows无法在命名空间系统
存在。我试图像几个组合:
I saw some people recommending the inclusion of a directive: using System.Windows.Media
; - I tried it and it triggered this error: Windows does not exist in namespace System
. I tried several combinations like:
btn.BackColor = Color.Red;
btn.Background = Brushes.Green;
和既不是工作。需要使用颜色特殊的指令?什么code你建议。非常感谢。
And neither is working. Is a special directive needed for using colour? What code do you suggest. Thanks a lot.
推荐答案
这应该改变你的按钮的背景颜色为红色
This should change your button background color to Red
yourButtonName.BackColor = Color.Red;
您需要包括 System.Drawing中命名空间Color类属于这一点。像这样
You need to include System.Drawing namespace as Color class belongs to that. Like this
using System.Drawing;
和ofcourse您需要添加在你的项目中使用此命名空间和颜色类参考 System.Drawing中
DLL。
And ofcourse you need to add the reference to System.Drawing
DLL in your project to use this namespace and Color class.
这篇关于按钮的背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!