| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 412 人关注过本帖
标题:求窗体关闭事件时保存到文件的代码
只看楼主 加入收藏
小爺の霸気
Rank: 2
等 级:论坛游民
帖 子:33
专家分:80
注 册:2011-3-20
结帖率:85.71%
收藏
 问题点数:0 回复次数:0 
求窗体关闭事件时保存到文件的代码
求窗体关闭事件时保存到文件的代码 要求执行Formclosing时 将信息保存到文件中去
我这有窗体添加图片的代码
 private void addPicture()
        {
            this.openPictureFile.Filter = "图片文件|*.gif;*.jpg;*.bmp;*.png";
            if (this.openPictureFile.ShowDialog() == DialogResult.OK)
            {
                if (this.treeViewShow.Nodes.Count == 0)
                {
                    MessageBox.Show("请填入分类名称", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    if (this.treeViewShow.SelectedNode.Parent == null)
                    {
                        if (this.openPictureFile.FileNames != null)
                        {
                            for (int i = 0; i < openPictureFile.FileNames.Length; i++)
                            {
                                //将图片的路径赋给pictureUrl
                                string pictureUrl = openPictureFile.FileNames[i];
                                //将图片的名称赋给pictureName
                                string pictureName = this.openPictureFile.FileNames[i].Split('\\')[this.openPictureFile.FileNames[i].Split('\\').Length - 1];
                                //将图片的分类赋给pictureClass
                                string pictureClass = this.treeViewShow.SelectedNode.ToString();
                                //将图片的路径、分类、名称加到集合里
                                this.myArrayList.Add(new Picture(openPictureFile.FileNames[i], pictureClass, pictureName));
                                //给TreeView 中添加图片
                                TreeNode tmp;
                                tmp = new TreeNode(pictureName);
                                treeViewShow.SelectedNode.Nodes.Add(tmp);
                                treeViewShow.SelectedNode.ExpandAll();
                            }

                        }
                    }
                    else
                    {
                        this.treeViewShow.SelectedNode = this.treeViewShow.SelectedNode.Parent;
                        for (int i = 0; i < openPictureFile.FileNames.Length; i++)
                        {
                            //将图片的路径赋给pictureUrl
                            string pictureUrl = openPictureFile.FileNames[i];
                            //将图片的名称赋给pictureName
                            string pictureName = this.openPictureFile.FileNames[i].Split('\\')
                           [this.openPictureFile.FileNames[i].Split('\\').Length - 1];
                            //将图片的分类赋给pictureClass
                            string pictureClass = this.treeViewShow.SelectedNode.ToString();
                            //将图片的路径、分类、名称加到集合里
                            this.myArrayList.Add(new Picture(openPictureFile.FileNames[i], pictureClass, pictureName));
                            //给TreeView 中添加图片
                            TreeNode tmp;
                            tmp = new TreeNode(pictureName);
                            treeViewShow.SelectedNode.Nodes.Add(tmp);
                            treeViewShow.SelectedNode.ExpandAll();
                        }
                    }
                    //this.showName();
                }
            }
        }
打开窗体读取文件信息的代码是
private void load()
        {
            //判断类别文件是不是存在,如果存在就读取数据
            if ((Application.StartupPath + "\\class.dat"))
            {
                //创建StreamReader实例,路径是在当前运行程序的目录下
                myReadClass = new (Application.StartupPath + "\\class.dat");
                string infoclass = "";
                //判断是不是到文件的末尾
                while ((infoclass = myReadClass.ReadLine()) != "end")
                {
                    this.treeViewShow.Nodes.Add(infoclass);
                }
                //关闭文件的读写
                myReadClass.Close();
            }
            //判断图片信息文件是不是存在,如果存在就读取数据。
            if ((Application.StartupPath + "\\picdata.dat"))
            {
                //创建StreamReader实例,路径是在当前运行程序的目录下。
                myReadPicture = new (Application.StartupPath + "\\picdata.dat");
                string infoPic = "";
                //判断是不是到文件的末尾
                while ((infoPic = myReadPicture.ReadLine()) != "end")
                {
                    string[] myPictureMessage = infoPic.Split(',');
                    //以“,”分开读取的信息,并存到数组中。
                    //判断数组是不是等于3。
                    if (myPictureMessage.Length >= 3)
                    {
                        //向动态数组中加入Picture类的实例。
                        this.myArrayList.Add(new Picture(myPictureMessage[2],myPictureMessage[0],myPictureMessage[1]));
                    }
                }
                for (int i = 0; i < this.treeViewShow.Nodes.Count; i++)
                {
                    for (int j = 0; j < this.myArrayList.Count; j++)
                    {
                        if (((Picture)myArrayList[j]).picClass == this.treeViewShow.Nodes[i].ToString())
                        {
                            this.treeViewShow.SelectedNode = this.treeViewShow.Nodes[i];
                            this.treeViewShow.SelectedNode.Nodes.Add(((Picture)myArrayList[j]).picName);
                        }
                    }
                }
                //关闭文件
                myReadPicture.Close();
            }
        }
但是窗体关闭时将添加图片的信息要怎么写啊  希望各位大大帮帮我
搜索更多相关主题的帖子: 图片 提示信息 private 
2011-04-26 21:03
快速回复:求窗体关闭事件时保存到文件的代码
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020282 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved