user153923
user153923

Reputation:

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.

So, given a System.Drawing.Color color, how would I create a 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; non-static is only Clone.

EDIT: (Resolved - thanks SLaks)

Using System.Drawing.SolidBrush, I am able to write:

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

Upvotes: 1

Views: 2950

Answers (1)

SLaks
SLaks

Reputation: 887877

You're seeing the WPF SolidColorBrush.
WPF itself is new to .Net 3.0.

The GDI+ (System.Drawing) SolidBrush class has always existed.

Upvotes: 4

Related Questions