[英]system.drawing reference
I'm trying to set the backColor of a text box like this: 我正在尝试设置文本框的backColor,如下所示:
txtCompanyName.BackColor = Drawing.Color.WhiteSmoke;
It doesn't like it because it wants me to add System in front like: 它不喜欢它,因为它希望我在前面添加系统,如:
txtCompanyName.BackColor = System.Drawing.Color.WhiteSmoke;
Now that works, but it irritates me that I have to type System. 现在这样有效,但是我必须输入System才会让我感到恼火。 I'm referencing System at the top of my code with using System; 我使用System在我的代码顶部引用System; Shouldn't that do the trick so I don't have to type System in front of drawing, not sure why I still have to type System, anybody know? 不应该这样做,所以我不必在绘图前键入System,不知道为什么我仍然要输入System,有人知道吗?
In C# you can't specify a type name by means of a partial namespace. 在C#中,您无法通过部分名称空间指定类型名称。 In C# the name must either be 在C#中,名称必须是
The Drawing
portion of Drawing.Color.WhiteSmoke
is a non-fully qualified namespace and hence illegal as a type name. Drawing.Color.WhiteSmoke
的Drawing
部分是一个非完全限定的命名空间,因此非法作为类型名称。 You either need to add the prefix System
or add a using System.Drawing
and change the type name to Color.WhiteSmoke
您需要添加前缀System
或using System.Drawing
添加,并将类型名称更改为Color.WhiteSmoke
Alternatively you can create an alias for the System.Drawing
namespace named Drawing
. 或者,您可以为名为Drawing
的System.Drawing
命名空间创建别名。
using Drawing = System.Drawing;
It is legal to use the alias as the start of a type name in C#. 将别名用作C#中类型名称的开头是合法的。
Easily fixed: 轻松修复:
using Drawing = System.Drawing;
...
txtCompanyName.BackColor = Drawing.Color.WhiteSmoke;
The using statement is importing the types that are in the specified namespace; using语句正在导入指定命名空间中的类型; this does not include child namespaces. 这不包括子命名空间。
If you really wanted, you could use the following line: 如果你真的想要,你可以使用以下行:
using Drawing = System.Drawing;
which would allow you to refer to the System.Drawing namespace as 'Drawing'. 这将允许您将System.Drawing命名空间称为“绘图”。 This is probably not the best solution though. 这可能不是最好的解决方案。 Really you should just use: 真的你应该使用:
using System.Drawing;
your line then becomes: 你的线然后变成:
txtCompanyName.BackColor = Color.WhiteSmoke;
if you need to disambiguate between System.Drawing.Color and some other Color class (like Microsoft.Xna.Framework.Color) you can use lines like this: 如果你需要消除System.Drawing.Color和其他一些Color类(如Microsoft.Xna.Framework.Color)之间的歧义,你可以使用这样的行:
using XNAColor = Microsoft.Xna.Framework.Color;
using WinColor = System.Drawing.Color;
then your line is: 那你的路线是:
txtCompanyName.BackColor = WinColor.WhiteSmoke;
You're using system, but you aren't using System.Drawing. 您正在使用系统,但您没有使用System.Drawing。 Add using System.Drawing;
using System.Drawing;
添加using System.Drawing;
to the rest of your using statements. 到其余的使用陈述。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.