简体   繁体   English

不使用SolidColorBrush从Color获取画笔

[英]Get Brush from Color without SolidColorBrush

It looks like the SolidColorBrush requires .NET 3 or up, and I have a requirement to keep away from requiring manufacturing computers go through an upgrade. 看起来SolidColorBrush需要.NET 3或更高版本,并且我要求不要求制造计算机进行升级。

So, given a System.Drawing.Color color , how would I create a System.Drawing.Brush ? 因此,给定System.Drawing.Color color ,我将如何创建System.Drawing.Brush

public static Brush GetBrush(Color color) {
  Brush result = Brushes.Black;
  // What goes here?
  return result;
}

The only static methods I see in Brushes are Equals and ReferenceEquals ; 我在Brushes中看到的唯一静态方法是EqualsReferenceEquals ; non-static is only Clone . 非静态只是Clone

EDIT: (Resolved - thanks SLaks ) 编辑:(已解决 - 感谢SLaks

Using System.Drawing.SolidBrush , I am able to write: 使用System.Drawing.SolidBrush ,我能够写:

public static Brush GetBrush(Color color) {
  if (color != Color.Empty) {
    return new SolidBrush(color);
  }
  return Brushes.Black;
}

You're seeing the WPF SolidColorBrush. 你看到的是WPF SolidColorBrush。
WPF itself is new to .Net 3.0. WPF本身是.Net 3.0的新手。

The GDI+ (System.Drawing) SolidBrush class has always existed. GDI +(System.Drawing) SolidBrush一直存在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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