Strange namespace problem

I am trying to use the System.Drawing.Color namespace. I cannot define it at the top of the class:

enter image description here

However, I can reference it inside the class. That is, I can use this line of code, and it works:

txtBox.BackColor = System.Drawing.Color.LightPink; 

... but I would just like to do this:

 txtBox.BackColor = Color.LightPink; 

If this is a question of missing a / dll link, why can I link to System.Drawing.Color in my code?

+4
source share
5 answers

This is because it is not a namespace. System.Drawing is the namespace, and Color is the structure ( struct ).

EDIT: Also, I would suggest using a product like ReSharper , which can fix such things almost automatically. ReSharper Rules!

0
source

System.Drawing.Color is a structure. Namespace - System.Drawing

0
source

Have you added a link to: System.Drawing in your References project?

0
source

You must add it to your links - somehow it is missing.

then you should declare using System.Drawing; at the top of your C # code, after which you can call Color.LightPink;

0
source

All Articles