Question

I'm in vb.net and I'm trying to format a print document. One of the non-negotiable attributes of it in one corner I have to a have a string with a black background and white text. I'm trying to use the DrawString and I can change the brush color , but I don't see anyway to change the BackColor.

Does anyone know if this is possible, or do I have to do something slightly more complex like doing it in two steps where I draw a rectangle and make that black, then put the string with a white brush color on top of it.

Thanks in advance if anyone can help.

    Dim Lgraph As Graphics = e.Graphics


    Dim rec As System.Drawing.Rectangle
    rec.X = 30
    rec.Y = 0
    rec.Width = 70
    rec.Height = 50

    Lgraph.DrawRectangle(Pens.Black, balls)

    Lgraph.DrawString(lblSku.Text.Substring(3, 4), New Font("Arial", 18, FontStyle.Regular), Brushes.Blue, rec)

This does pretty much what I want it to, however, i want to FILL the rectangle with a specific color, where as the Pens.Black just makes the border the chosen color.

Was it helpful?

Solution

I'm afraid you will have to do it in two steps, first coloring the rectangle, and then adding the colored text to it. the Graphics.DrawString methods do not allow you to create or manipulate the rectangle within the call. Luckilly they do allow you to pass in the rectangle though, so shouldn't be too much trouble.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top