Erasing lines
-
Hi all, I am making an application, where i need to keep drawing and erasing lines over an image. Drawing lines is ok, but i am not able to find any suitable means to remove those lines. One method could be to draw on the same line using some other color, but that method is unsuitable since i am drawing it over an image.:( Another method could be to send the Paint event so as to refresh the frame. But since i am drawing and removing the lines quite frequently, i dont think it will be a good idea to call the paint method so many times. Can anyone please suggest a more efficient method?:confused: Any help will be highly appreciated. Thanks in advance.:cool: *** Who said nothing is impossible? I have been doing it for a long time ***
-
Hi all, I am making an application, where i need to keep drawing and erasing lines over an image. Drawing lines is ok, but i am not able to find any suitable means to remove those lines. One method could be to draw on the same line using some other color, but that method is unsuitable since i am drawing it over an image.:( Another method could be to send the Paint event so as to refresh the frame. But since i am drawing and removing the lines quite frequently, i dont think it will be a good idea to call the paint method so many times. Can anyone please suggest a more efficient method?:confused: Any help will be highly appreciated. Thanks in advance.:cool: *** Who said nothing is impossible? I have been doing it for a long time ***
Repainting is generally a good idea. Just implement your OnPaint method the way that a flag indicates whether the lines should be drawn or not. Everytime you switch between on and off just switch the flag and call Invalidate on your control. This will lead to a repaint (and also avoid too many repaints). If your are switching frequently you should enable double buffering to avoid flickering: (in constructor)
base.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.DoubleBuffer | ControlStyles.UserPaint, true);
-
Repainting is generally a good idea. Just implement your OnPaint method the way that a flag indicates whether the lines should be drawn or not. Everytime you switch between on and off just switch the flag and call Invalidate on your control. This will lead to a repaint (and also avoid too many repaints). If your are switching frequently you should enable double buffering to avoid flickering: (in constructor)
base.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.DoubleBuffer | ControlStyles.UserPaint, true);