简体   繁体   中英

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:

在此处输入图片说明

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?

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.DrawingReferences

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM