Search code examples
c#.netsystem.drawing

Drawing String with Graphics c#


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


Solution

  • 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.