开发者

How to deal with System.Drawing.Color <--> System.Windows.Media.Color ambiguous reference

I'm using System.Drawing to fill rectangles and draw 开发者_开发技巧lines and stuff. The System.Drawing.Color object only has a list of pre-defined colors, and I want to assign my own colors using RGB. So I've added the System.Windows.Media namespace, and now all references to "Color" say they're a ambiguous references.

I understand why. But I am wondering if there is a better solution than doing this

System.Windows.Media.Color colorVariableName;

wherever I reference a Color variable.


You're able to alias your usings at the top, so you can say something like

using MediaColor = System.Windows.Media.Color

And you'll be able to say

MediaColor colorVariableName


With System.Drawing.Color, you can do

Color c = Color.FromArgb(255,255,255);

to initialize color from your own R, G and B values and maybe you can skip System.Windows.Media.Color


Use Color.FromArgb(r, g, b)) to convert from rgb to System.Color. r,g, and b are ints


The other option would be to alias one of the namespaces in the using clause like so:

using System.Windows.Media = med;

Then you can access the colours with:

med.Blue

Also if it's just that particular class that you're interested in you can give that an alias in the using clause also.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜