0

I am using C# windows form

this code creates a transparent color named "newColor"

            Color newColor = Color.FromArgb(100, Color.Red);

and here is the code I where I use the Brush

e.Graphics.FillEllipse(Brushes.newColor, mpo.X, mpo.Y, 2, 2);

but it's not working, and displays:

Error 1 'System.Drawing.Brushes' does not contain a definition for 'newColor

how to use a C# brush with a transparent color?

McGarnagle
  • 101,349
  • 31
  • 229
  • 260
Zahema
  • 1,345
  • 2
  • 19
  • 35

1 Answers1

6

Just creating a Color object doesn't magically add it to the pre-defined list in Brushes.

You need to do this:

e.Graphics.FillEllipse(new SolidBrush(newColor), mpo.X, mpo.Y, 2, 2);

To use the color you just created. Credit to System.Drawing.Brush from System.Drawing.Color for how to create a brush from a color.

Community
  • 1
  • 1
BradleyDotNET
  • 60,462
  • 10
  • 96
  • 117