Trying to erase a line

Hi. I have a little problem that is bugging me. I have a canvas. I set the forecolor to white and fill the entire canvas, using “fillrect.” Then I reset the forecolor to blue, and use “drawline” to draw a line from upper left to lower right. Later on in my code, I change the color back to white, and redraw that same line. I expected the blue line to be erased. Instead, I have a pale blue copy of my original line. Can anybody suggest what is going on here? By the way I tried the same thing, using a picture. Same result.

Where are you doing this drawing code? In the paint event?
Probably the easiest way to “erase” the line is to not draw it. In the paint event, set a boolean to either draw the line or not. Then, making sure the boolean is set as desired, just call .invalidate on the canvas.

Thanks, Roger. But I was just trying to understand why I didn’t get my expected result.

OS anti-aliasing (because it is a diagonal line) is the reason. You can turn it off with g.AntiAlias = False in the Paint event handler.

Hey, Paul! Wow! Thank you. That’s perfect.