C# cleaning screen problem.

Hello!

I have that program written in C#:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DrawingPROGRAM
{
   
    public partial class Form1 : Form
    {
        public Form1()
        {
               InitializeComponent();
                  
        }
        
        private void bDraw_Click(object sender, EventArgs e)
        {
            int n;
            n = Convert.ToInt32(Number_Box.Text);
            Graphics g = this.CreateGraphics();
           
            Pen p = new Pen(Color.Blue, 2);
            
            
            int[] v_x = new int[30];
            int[] v_y = new int[30];
            int [,] mat_adiac = new int[100,100];
            
            double pas, poz=0, zoom;

            zoom = Convert.ToDouble(zoom_box.Text);

            // initializam matricea de adiacenta cu 1, pentru ca vrem sa desenam un graf complet

            for(int i=1; i<n; i++)
            {  for(int j=i+1; j<=n; j++)
               {   
                  mat_adiac[i,j] = 1;
                  mat_adiac[j,i] = mat_adiac[i,j];
               } 
            }

            // initializam niste variabile care ne folosesc la crearea vectorilor de coordonate

            pas = 2*3.14159265358979/n;
 
            // ii zicem zoom = 100;

            

            // initializam vectorii de coordonate:

            for(int i=1; i<=n; i++)
            {  
                 v_x[i] = Convert.ToInt32(Math.Floor(320 + 2* zoom * Math.Cos(poz)));
                 v_y[i] = Convert.ToInt32(Math.Floor(240 + 2 * zoom * Math.Sin(poz)));
                 poz = poz + pas;
            }

             
            for (int i = 1; i <= n; i++)
            {
                
                g.FillEllipse(p.Brush, new Rectangle(v_x[i], v_y[i], 15, 15));
                
             }

            for (int i = 1; i < n; i++)
            {
                for (int j = i + 1; j <= n; j++)
                {
                    if (mat_adiac[i, j] == 1)
                        g.DrawLine(p, new Point(v_x[i], v_y[i]), new Point(v_x[j], v_y[j]));
                    
                }
            }
                 
        
        }
        private void button1_Click(object sender, EventArgs e)
        {
            
        }

        
    }
}


That program draws some lines and points (ellipses).


The last method belongs to a button (I've created a button in design - mode and I double-clicked it). I want that, when I press that button, to earse all that was drawn on the screen. I know that I have a function Clear() that I can call from a Graphics variable, for instance g.Clear() but I can't do that because I've declared the Graphics variable in the previous function, so I can't use the g variable in that clear-button function.

Thank you respectfully.
This is a C++ forum. For C# post questions @ MSDN: http://social.msdn.microsoft.com/Forums. There are specialized Windows Forms forums there.
Why not make Graphics g a member of the class then just g = this.CreateGraphics() and g.Clear() in the respective functions.
I've got the idea. web Jose: sorry but I was in a hurry and I thought that might be someone around here specialized in C#.

naraku9333: that worked. Thanks a lot.
Topic archived. No new replies allowed.