Remove Lines at runtime

Total Post:9

Points:63
C# 
 1058  View(s)
Ratings:
Rate this:
Hi
I.m drawing number of lines at runtime in windows form application using Pen.Now I want to remove some of the lines by clicking MouseRight button at runtime.Is it possible?.If possible then tell me the code using c#.Please help me anyone.

Thanks.
  1. Post:26

    Points:188
    Re: Remove Lines at runtime

     The Graphics.Draw... functions replace the pixels. There is no way to undo that unless you either

      1. store the pixels that are being changed so you can reverse the drawing or
      2. draw the pixels on a copy of the desktop so you can revert to the actual desktop or
      3. overlay the desktop with a transparent surface and draw on that and remove the surface  when it is no longer  needed.
    You can use  Invalidate(); method for reset your lines

    private void button1_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
          
            }
            if (e.Button == MouseButtons.Right)
            {
                    this.Invalidate();
            }
        }

      Modified On Apr-09-2018 05:25:32 AM

Answer