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?
Reasons I can think of why System.Drawing could be filtered in the usings dropdown:
Caution: Classes within the System.Drawing namespace are not supported for use within a Windows or ASP.NET service. 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
That's because it isn't a namespace. System.Drawing
is the namespace, and Color
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!
System.Drawing.Color is a struct. Namespace is 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;
in the top portion of your C# code then you can call Color.LightPink;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.