---
title: "Remove Lines at runtime"  
description: "Remove Lines at runtime"  
author: "Jaya J"  
published: 2015-04-28  
updated: 2015-04-29  
canonical: https://www.mindstick.com/forum/23155/remove-lines-at-runtime  
category: ".net"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Remove Lines at runtime

HiI.m drawing number of lines at [runtime](https://www.mindstick.com/articles/52/creating-timer-at-runtime-in-c-sharp-dot-net) in [windows](https://www.mindstick.com/articles/311752/how-to-install-and-use-the-google-wifi-software-on-a-windows-or-mac-computer) [form application](https://www.mindstick.com/interview/23108/how-to-create-form-application-using-dot-net) using Pen.Now I want to [remove](https://yourviews.mindstick.com/story/4554/8-harmful-weeds-to-remove-from-garden) some of the lines by clicking MouseRight [button](https://www.mindstick.com/articles/63/how-to-add-button-in-datagridview-in-csharp-dot-net) at runtime.Is it possible?.If possible then tell me the [code using c#](https://www.mindstick.com/forum/34226/how-to-print-qr-code-using-c-sharp-windows-form).Please help me anyone.\
Thanks.

## Replies

### Reply by Manoj Pandey

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();        }    }
```


---

Original Source: https://www.mindstick.com/forum/23155/remove-lines-at-runtime

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
