命名空间的奇怪问题
我正在尝试使用 System.Drawing.Color 命名空间。我无法在类的顶部定义它:
但是,我可以在其中引用它班级。也就是说,我可以使用这行代码,并且它可以工作:
txtBox.BackColor = System.Drawing.Color.LightPink;
...但我宁愿能够这样做:
txtBox.BackColor = Color.LightPink;
如果这是缺少引用/dll 的问题,为什么我能够引用 System我的代码中的.Drawing.Color?
I'm trying to use the System.Drawing.Color namespace. I'm not able to define it at the top of the class:
However, I can reference it within the class. That is, I can use this line of code, and it works:
txtBox.BackColor = System.Drawing.Color.LightPink;
... but I'd rather just be able to do this:
txtBox.BackColor = Color.LightPink;
If it's a matter of a missing reference/dll, why am I able to make reference to System.Drawing.Color in my code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我能想到为什么 System.Drawing 可以在 usings 下拉列表中进行过滤的原因:
http://msdn.microsoft.com/en-us/library/system.drawing(v=VS.100).aspx
Reasons I can think of why System.Drawing could be filtered in the usings dropdown:
http://msdn.microsoft.com/en-us/library/system.drawing(v=VS.100).aspx
那是因为它不是命名空间。
System.Drawing
是命名空间,Color
是一个结构体 (struct
)。编辑:此外,我建议使用诸如 ReSharper 之类的产品,它可以纠正这样的问题几乎自动地。 ReSharper 规则!
That's because it isn't a namespace.
System.Drawing
is the namespace, andColor
is a structure (struct
).EDIT: Additionally, I'd advise to use a product such as ReSharper, which can correct stuff like this almost automagically. ReSharper rules!
您是否在项目
References
中添加了对:System.Drawing
的引用?Did you add a reference to:
System.Drawing
in your projectReferences
?你必须将它添加到你的参考文献中 - 不知何故它丢失了。
那么您必须在 C# 代码的顶部声明
using System.Drawing;
然后您可以调用Color.LightPink;
You have to add it to your references - somehow it is missing.
then you have to declare
using System.Drawing;
in the top portion of your C# code then you can callColor.LightPink;
System.Drawing.Color 是一个结构体。
命名空间是 System.Drawing
System.Drawing.Color is a struct.
Namespace is System.Drawing