Answered by:
Background color for method Graphic.DrawString()

Question
-
Use VS 2010, VB.NET, .NET Framework 4, Windows 7How I can set background color for method Graphic.DrawString()?I use this code for write text on image:
Graphic.DrawString(Text, InstFont, InstBrush, TextPosition)<br/>
- Edited by Mahno.net Tuesday, November 8, 2011 2:51 PM
Answers
-
You don't specify a background color.
The background color is whatever you draw on (just like using a pen or pencil - the paper color is already set). If you need to have a different color, you can use FillRectangle() and use MeasureString() to determine how big a rectangle you need to draw.
Stephen J Whiteley- Proposed as answer by Waleed El-Badry Tuesday, November 8, 2011 3:23 PM
- Marked as answer by Mahno.net Tuesday, November 8, 2011 8:16 PM
All replies
-
You don't specify a background color.
The background color is whatever you draw on (just like using a pen or pencil - the paper color is already set). If you need to have a different color, you can use FillRectangle() and use MeasureString() to determine how big a rectangle you need to draw.
Stephen J Whiteley- Proposed as answer by Waleed El-Badry Tuesday, November 8, 2011 3:23 PM
- Marked as answer by Mahno.net Tuesday, November 8, 2011 8:16 PM
-
Hi, I quoted this code from the msdn documentation found here
Public Sub DrawStringPointF(ByVal e As PaintEventArgs) ' Create string to draw. Dim drawString As [String] = "Sample Text" ' Create font and brush. Dim drawFont As New Font("Arial", 16) Dim drawBrush As New SolidBrush(Color.Black) ' Create point for upper-left corner of drawing. Dim drawPoint As New PointF(150.0F, 150.0F) ' Draw string to screen. e.Graphics.DrawString(drawString, drawFont, drawBrush, drawPoint) End Sub
Make sure that you used the following code inside the paint event of your form.Hope it helps
P.S: I thought you were wondering about the parameters passed to the method. Regarding your question, I do agree wth SJWhiteley.
Waleed El-Badry, Mechatronics Department, College of Engineering, Misr University for Science and Technology View my MCP Certifications- Edited by Waleed El-Badry Tuesday, November 8, 2011 3:24 PM
-
You can do that using the HatchBrush.
http://msdn.microsoft.com/en-us/library/system.drawing.drawing2d.hatchbrush.aspx
Another way is drawing three times.
Success
Cor -
How I can set background color for method Graphic.DrawString()?I use this code for write text on image:
Graphic.DrawString(Text, InstFont, InstBrush, TextPosition)<br/>