After form minimzing my graphic shapes are losing. How can I solve this problem?
Asked
Active
Viewed 259 times
1 Answers
6
My psychic debugging skills tell me that you're drawing using CreateGraphics()
.
You need to draw all of your graphics in the Paint
event so that they get redrawn whene the form gets repainted.
You should never draw using CreateGraphics()
.

SLaks
- 868,454
- 176
- 1,908
- 1,964
-
Yes, I have drawn using CreateGraphics, because I need to paint shapes on the button click. How can I get PaintEvntArgs on the button click? – dotNet_d19 Jun 30 '13 at 15:54
-
1@dotNet_d19: You can't. You need to draw **in the paint event** so that it can redraw at will. Instead, you need to keep track of what to draw on every paint and call `Invalidate()`. – SLaks Jun 30 '13 at 15:57
-
Can you explain in detail? I must draw on the button click, because I set the count of shapes from form. – dotNet_d19 Jun 30 '13 at 16:04
-
Basically you keep the information about what to draw at **Class** level (a List
might be helpful!). Then, in the `Paint()` event, use the supplied Graphics via `e.Graphics` and iterate over the information in your class level variable and draw everything. I already gave you an [example](http://stackoverflow.com/a/17384089/2330053) in your **previous** question. Just follow that basic model...it doesn't have to be a GraphicsPath in the List, you can create a custom Class to represent whatever needs to be drawn. – Idle_Mind Jun 30 '13 at 16:09