Search code examples
c#asp.netwinformsusing-statement

Weird issue with namespace


I'm trying to use the System.Drawing.Color namespace. I'm not able to define it at the top of the class:

enter image description here

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?


Solution

  • 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!