@@ -12,20 +12,49 @@ namespace Jthomson.Maze
12
12
{
13
13
public partial class Form1 : Form
14
14
{
15
+ BufferedPanel displayPanel ;
16
+ Maze m ;
17
+
15
18
public Form1 ( )
16
19
{
17
20
InitializeComponent ( ) ;
21
+ displayPanel = new BufferedPanel ( ) ;
22
+ displayPanel . Anchor = (
23
+ AnchorStyles . Top |
24
+ AnchorStyles . Bottom |
25
+ AnchorStyles . Left |
26
+ AnchorStyles . Right
27
+ ) ;
28
+ displayPanel . Location = new System . Drawing . Point ( 12 , 84 ) ;
29
+ displayPanel . Size = new System . Drawing . Size ( 504 , 507 ) ;
30
+ displayPanel . Paint += ( sender , e ) =>
31
+ {
32
+ if ( m != null )
33
+ {
34
+ m . Draw ( e . Graphics , new Pen ( Color . Black ) ) ;
35
+ }
36
+ } ;
37
+ this . Controls . Add ( displayPanel ) ;
18
38
}
19
39
20
- private void btnDraw_Click ( object sender , EventArgs e )
40
+ private void btnUpdate_Click ( object sender , EventArgs e )
21
41
{
22
42
int rows = trkRows . Value ;
23
43
int cols = trkCols . Value ;
24
- Maze m = new Maze ( cols , rows ) ;
44
+ m = new Maze ( cols , rows ) ;
25
45
m . Generate ( ) ;
26
46
m . CellSize = 10 ;
27
- pctDisplay . CreateGraphics ( ) . Clear ( pctDisplay . BackColor ) ;
28
- m . Draw ( pctDisplay . CreateGraphics ( ) , new Pen ( Color . Black ) ) ;
47
+ displayPanel . Invalidate ( ) ;
48
+
49
+ }
50
+
51
+ private class BufferedPanel : Panel
52
+ {
53
+ public BufferedPanel ( ) : base ( )
54
+ {
55
+ this . DoubleBuffered = true ;
56
+ this . ResizeRedraw = true ;
57
+ }
29
58
}
30
59
}
31
60
}
0 commit comments