[英]Weird issue with namespace
I'm trying to use the System.Drawing.Color namespace. 我正在尝试使用System.Drawing.Color命名空间。 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? 如果是缺少引用/ dll的问题,为什么我可以在代码中引用System.Drawing.Color?
Reasons I can think of why System.Drawing could be filtered in the usings dropdown: 我可以想到为什么可以在usings下拉列表中过滤System.Drawing的原因:
Caution: Classes within the System.Drawing namespace are not supported for use within a Windows or ASP.NET service.
警告:不支持在Windows或ASP.NET服务中使用System.Drawing命名空间中的类。 Attempting to use these classes from within one of these application types may produce unexpected problems, such as diminished service performance and run-time exceptions.
尝试从这些应用程序类型之一中使用这些类可能会产生意外问题,例如服务性能下降和运行时异常。
http://msdn.microsoft.com/en-us/library/system.drawing(v=VS.100).aspx http://msdn.microsoft.com/zh-CN/library/system.drawing(v=VS.100).aspx
That's because it isn't a namespace. 那是因为它不是名称空间。
System.Drawing
is the namespace, and Color
is a structure ( struct
). System.Drawing
是名称空间,而Color
是结构( struct
)。
EDIT: Additionally, I'd advise to use a product such as ReSharper , which can correct stuff like this almost automagically. 编辑:另外,我建议您使用ReSharper之类的产品,该产品几乎可以自动纠正此类问题。 ReSharper rules!
ReSharper规则!
System.Drawing.Color is a struct. System.Drawing.Color是一个结构。 Namespace is System.Drawing
命名空间为System.Drawing
您是否在项目References
添加了对System.Drawing
的References
?
You have to add it to your references - somehow it is missing. 您必须将其添加到参考中-某种程度上它是丢失的。
then you have to declare using System.Drawing;
那么您必须
using System.Drawing;
进行声明using System.Drawing;
in the top portion of your C# code then you can call Color.LightPink;
在C#代码的顶部,您可以调用
Color.LightPink;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.