Question

The task is to draw a moving text on a black background (for example, a moving number) with .NET GDI+. Some other elements may present on this background, so it isn't possible to fill all the area with black and then draw a string in a new position.

My current code is as follows:

Graphics g = this.CreateGraphics();
// drawing a string
Font myFont = new Font("Fixedsys", 10);
g.DrawString("1", myFont, Brushes.Gray, 100, 100);
// erasing a string
g.DrawString("1", myFont, Brushes.Black, 100, 100);

// then we repeat the code above with a new position for a string

The problem is that the text isn't erased entirely by the second DrawString with black brush. Small border remains visible. Please help, how to remove this trace, and draw moving text correctly.

Was it helpful?

Solution

The problem is solved by adding the following:

g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixel;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top