G
Guest
I'm drawing text using the DrawString method. I need a way to go back and
erase one or more characters. As a first thought it seemed that one way to
do it would be to go back to the character(s) I want to erase and merely
re-write the same character(s) using a brush whose foreground color is the
same as the background color. The following code does that:
protected override void OnPaint(PaintEventArgs pea)
{
Graphics grfx = pea.Graphics;
Brush brush = new SolidBrush(ForeColor);
Brush eraser = new SolidBrush(BackColor);
Point pt = AutoScrollPosition;
grfx.DrawString("ABC", Font, brush, pt.X, pt.Y);
grfx.DrawString("ABC", Font, eraser, pt.X, pt.Y);
grfx.DrawString("DEF", Font, brush, pt.X, pt.Y);
}
Although it works somewhat, there seems to be a "shadow" of some sort after
I replace ABC with DEF. I don't know if it's because the rewrite of ABC
using the background color doesen't exactly line up with the first write, or
something else. In any case, it seems that there must be a better approach.
As usual, thanks for your help in advance.
Ray
erase one or more characters. As a first thought it seemed that one way to
do it would be to go back to the character(s) I want to erase and merely
re-write the same character(s) using a brush whose foreground color is the
same as the background color. The following code does that:
protected override void OnPaint(PaintEventArgs pea)
{
Graphics grfx = pea.Graphics;
Brush brush = new SolidBrush(ForeColor);
Brush eraser = new SolidBrush(BackColor);
Point pt = AutoScrollPosition;
grfx.DrawString("ABC", Font, brush, pt.X, pt.Y);
grfx.DrawString("ABC", Font, eraser, pt.X, pt.Y);
grfx.DrawString("DEF", Font, brush, pt.X, pt.Y);
}
Although it works somewhat, there seems to be a "shadow" of some sort after
I replace ABC with DEF. I don't know if it's because the rewrite of ABC
using the background color doesen't exactly line up with the first write, or
something else. In any case, it seems that there must be a better approach.
As usual, thanks for your help in advance.
Ray