In this tutorial I will show you how to set background for text using Graphics.DrawRectangle in c#.
C# CODE FOR TEXT & BACKGROUND:
//background added
Brush brs = new SolidBrush(Color.Red);
System.Drawing.SizeF stringSize = graphics.MeasureString(text, font);
graphics.FillRectangle(new SolidBrush(Color.Black), 0, 0, stringSize.Width, stringSize.Height);
graphics.DrawString(text, font, brs, 0, 0);
OUTPUT: