选择显示字体大小

序列化和反序列化xml应用程序设置类

  1        public class applicationsettings
  2        {
  3
  4            private bool appsettingschanged;
  5            // 用于存储应用程序设置的变量。
  6
  7            private point formlocation;
  8       
  9            public point formlocation
 10            {
 11                get { return formlocation; }
 12                set
 13                {
 14                    if (value != formlocation)
 15                    {
 16                        formlocation = value;
 17                        appsettingschanged = true;
 18                    }
 19                }
 20            }
 21
 22
 23            // 从配置文件中反序列化类。
 24            public bool loadappsettings()
 25            {
 26                xmlserializer myserializer = null;
 27                filestream myfilestream = null;
 28                bool fileexists = false;
 29
 30                try
 31                {
 32                    // 为 applicationsettings 类型创建 xmlserializer。
 33                    myserializer = new xmlserializer(typeof(applicationsettings));
 34                    fileinfo fi = new fileinfo(application.localuserappdatapath
 35                       + @"\myapplication.config");
 36                    // 如果配置文件存在,将其打开。
 37                    if (fi.exists)
 38                    {
 39                        myfilestream = fi.openread();
 40                        // 反序列化配置文件以创建新的
 41                        // applicationsettings 实例。
 42                        applicationsettings myappsettings =
 43                          (applicationsettings)myserializer.deserialize(
 44                           myfilestream);
 45                        // 为 applicationsettings 类的这一实例
 46                        // 分配属性值。
 47                        this.formlocation = myappsettings.formlocation;
 48                        fileexists = true;
 49                    }
 50                }
 51                catch (exception ex)
 52                {
 53                    messagebox.show(ex.message);
 54                }
 55                finally
 56                {
 57                    // 如果 filestream 是打开的,将其关闭。
 58                    if (myfilestream != null)
 59                    {
 60                        myfilestream.close();
 61                    }
 62                }
 63
 64           
 65                return fileexists;
 66            }
 67
 68            // 如果设置发生变化,则将
 69            // 类序列化到配置文件中。
 70            public bool saveappsettings()
 71            {
 72                if (this.appsettingschanged)
 73                {
 74                    streamwriter mywriter = null;
 75                    xmlserializer myserializer = null;
 76                    try
 77                    {
 78                        // 为 applicationsettings 类型
 79                        // 创建 xmlserializer。
 80                        myserializer = new xmlserializer(
 81                          typeof(applicationsettings));
 82                        mywriter =
 83                          new streamwriter(application.localuserappdatapath
 84                          + @"\myapplication.config", false);
 85                        // 将 applicationsettings 类的这一实例
 86                        // 序列化到配置文件中。
 87                        myserializer.serialize(mywriter, this);
 88                    }
 89                    catch (exception ex)
 90                    {
 91                        messagebox.show(ex.message);
 92                    }
 93                    finally
 94                    {
 95                        // 如果 filestream 是打开的,将其关闭。
 96                        if (mywriter != null)
 97                        {
 98                            mywriter.close();
 99                        }
100                    }
101                }
102                return appsettingschanged;
103            }
104        }

出处:ting blog


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons