日期:2014-05-16  浏览次数:20827 次

一个关于xml清空数据的问题
我在代码中点击一下就会生成一个控件,还会把相应的信息以xml的形式保存下来。现在我点这个button点了10下,就意味着创建了10个相对应的xml信息。我把运行程序关掉,再打开再运行,发现之前目录下的xml文件还在。我要在关闭我的程序时加什么代码才能让我的xml文件在程序关闭时清空呢?
public XmlDocument document = new XmlDocument();private void pbBtn_MouseUp(object sender, MouseEventArgs e)
        {  
                if (this.create_Btn)
                {
                    Button button1 = null;
                    button1 = new Button();
                    button1.Width = 80;
                    button1.Height = 35;
                    button1.Name = "Button" + BtnCount;
                    button1.AutoSize = true;
                    button1.Text = "Button" + BtnCount;
                    button1.Location = new Point(e.X - 108, e.Y + 30);
                    button1.MouseDown += new System.Windows.Forms.MouseEventHandler(Button_MouseDown);
                    button1.MouseMove += new System.Windows.Forms.MouseEventHandler(Button_MouseMove);
                    button1.MouseUp += new System.Windows.Forms.MouseEventHandler(Button_MouseUp);
                    button1.MouseLeave += new System.EventHandler(MyMouseLeave);
                    button1.Enter += new System.EventHandler(BtnEnter);
                    button1.KeyDown += new KeyEventHandler(MykeyDown);
                    button1.KeyUp += new KeyEventHandler(MykeyUp);
                    button1.Cursor = System.Windows.Forms.Cursors.Default;
                    this.panel1.Controls.Add(button1); 
                    this.listbtn.Add(button1);
&n