开发者

System.Drawing.ColorTranslator.ToOle in silverlight 4

What is the equivalence of System.Drawing.ColorTranslator.ToOle in Silverlight 4 ?

Here's my Code:

.Range("C1:F23").Interior.Color = System.Drawing.ColorTranslator.ToOl开发者_开发知识库e(Color.FromArgb(100, 255, 255, 153)) '' This line is Failing..


ColorTranslator does not exist in Silverlight.

DotPeek shows the source for System.Drawing.ColorTranslator.ToOle() below:

public static int ToOle(Color c)
{
  if (c.IsKnownColor)
  {
    switch (c.ToKnownColor())
    {
      case KnownColor.ActiveBorder:
        return -2147483638;
      case KnownColor.ActiveCaption:
        return -2147483646;
      case KnownColor.ActiveCaptionText:
        return -2147483639;
      case KnownColor.AppWorkspace:
        return -2147483636;
      case KnownColor.Control:
        return -2147483633;
      case KnownColor.ControlDark:
        return -2147483632;
      case KnownColor.ControlDarkDark:
        return -2147483627;
      case KnownColor.ControlLight:
        return -2147483626;
      case KnownColor.ControlLightLight:
        return -2147483628;
      case KnownColor.ControlText:
        return -2147483630;
      case KnownColor.Desktop:
        return -2147483647;
      case KnownColor.GrayText:
        return -2147483631;
      case KnownColor.Highlight:
        return -2147483635;
      case KnownColor.HighlightText:
        return -2147483634;
      case KnownColor.HotTrack:
        return -2147483622;
      case KnownColor.InactiveBorder:
        return -2147483637;
      case KnownColor.InactiveCaption:
        return -2147483645;
      case KnownColor.InactiveCaptionText:
        return -2147483629;
      case KnownColor.Info:
        return -2147483624;
      case KnownColor.InfoText:
        return -2147483625;
      case KnownColor.Menu:
        return -2147483644;
      case KnownColor.MenuText:
        return -2147483641;
      case KnownColor.ScrollBar:
        return int.MaxValue;
      case KnownColor.Window:
        return -2147483643;
      case KnownColor.WindowFrame:
        return -2147483642;
      case KnownColor.WindowText:
        return -2147483640;
      case KnownColor.ButtonFace:
        return -2147483633;
      case KnownColor.ButtonHighlight:
        return -2147483628;
      case KnownColor.ButtonShadow:
        return -2147483632;
      case KnownColor.GradientActiveCaption:
        return -2147483621;
      case KnownColor.GradientInactiveCaption:
        return -2147483620;
      case KnownColor.MenuBar:
        return -2147483618;
      case KnownColor.MenuHighlight:
        return -2147483619;
    }
  }
  return ColorTranslator.ToWin32(c);
}

This uses members that also do not exist in Silverlight (Color.IsKnownColor & Color.ToKnownColor()) so you could just use the ToWin32() method it uses for everything except the "known colors":

public static int ToWin32(Color c)
{
  return (int) c.R | (int) c.G << 8 | (int) c.B << 16;
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜