---
title: "C# panel drawing on button press"  
description: "C# panel drawing on button press"  
author: "Anonymous User"  
published: 2013-11-13  
updated: 2013-11-13  
canonical: https://www.mindstick.com/forum/1715/c-sharp-panel-drawing-on-button-press  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# C# panel drawing on button press

I want to [update](https://www.mindstick.com/forum/156353/what-is-hummingbird-update) the [panel](https://www.mindstick.com/blog/11988/restructuring-corporate-offenses-government-appointed-panel-suggests-in-house-adjudication-system) [graphics](https://www.mindstick.com/articles/336067/html-graphics-using-html) (panel will contain [simple](https://yourviews.mindstick.com/story/1469/5-simple-ways-to-stay-fit-amp-healthy) shapes like circles and rectangles) every time a [button](https://www.mindstick.com/articles/63/how-to-add-button-in-datagridview-in-csharp-dot-net) is pressed. The [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) would look something like this:

```
private void PanelGraphics(){   
ClearThePanel();  //empties the
panel   
FillThePanel();   //draws new
shapes in the panel}
```

The [function](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) would be then called every time a button is pressed, and I understand button_events well [enough](https://answers.mindstick.com/qa/48601/who-is-the-writer-of-the-one-life-is-not-enough) so that's not a problem. However, I have no idea how to pull off the PanelGraphics() function, and a few [links](https://www.mindstick.com/blog/415/css3-links) about panel_paint [events](https://www.mindstick.com/blog/102/events-in-c-sharp) didn't help me much.

## Replies

### Reply by Anonymous User

Hi Chintoo,\

You can draw to the panel by creating a graphics controller to it.

Graphics g = panel.CreateGraphics();

You can then use the Graphic class's plethora of methods to draw whatever you want to the panel

```
g.DrawCurve(parameters);g.DrawEllipse(parameters);g.DrawLine(parameters);g.DrawRectangle(parameters);
```

To clear the panel the easiest way is to draw a box the colour of the background to the panel

g.DrawRectangle(new Pen(panel.BackColor), new Rectangle(new Point(), panel.Size));


---

Original Source: https://www.mindstick.com/forum/1715/c-sharp-panel-drawing-on-button-press

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
