开发者

Weird issue with namespace

I'm trying to use the System.Drawing.Color namespace. I'm not able to define it at the top o开发者_Go百科f the class:

Weird issue with namespace

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:

  1. it is already used ( -- nah, probably not, but anyway)
  2. you're in a ASP.NET Service:

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!


Did you add a reference to: System.Drawing in your project 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;


System.Drawing.Color is a struct. Namespace is System.Drawing

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜