-1

how to draw string with graphics in c#? I tried with this code but it dose not work. Thanks.

g.DrawString("STRING", new Font(this.Font, FontStyle.Bold), 
                       new Brush(), new Point(100, 100));

Error:

Error 1 Cannot create an instance of the abstract class or interface 'System.Drawing.Brush' C:\Users\Mihai\AppData\Local\Temporary Projects\Graphics Drawtext\Form1.cs 33 73 Graphics Drawtext

Andrey Korneyev
  • 26,353
  • 15
  • 70
  • 71
Mihai
  • 17
  • 5
  • Instead of passing new Brush() pass new SolidBrush(Color.Black) – Adil Apr 07 '17 at 09:14
  • 1
    that was it thanks! – Mihai Apr 07 '17 at 09:20
  • Or use a standard Brushes.Black brush. If you create one of oyur own (makes only sense if you use a special color, esp. a semi-transparent color) do not forget to dispose of it!! – TaW Apr 07 '17 at 09:37

1 Answers1

2

Instead of abstract Brush you have to create concrete one - for example SolidBrush (or any other of your choice).

See MSDN for the list of brush implementations (classes derive from Brush) you can use.

Andrey Korneyev
  • 26,353
  • 15
  • 70
  • 71