企業類庫之Configuration-Migration Application Block(一)
EditorFontData.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;

namespace Demo003
...{
    
/**//// <summary>
    
/// 
    
/// </summary>

    public class EditorFontData:ConfigurationSection
    
...{
        
/**//// <summary>
        
/// 
        
/// </summary>

        public EditorFontData()
        
...{
        }


        
/**//// <summary>
        
/// 
        
/// </summary>

        ~EditorFontData()
        
...{
        }


        
/**//// <summary>
        
/// 
        
/// </summary>

        [ConfigurationProperty("Name")]
        
public string Name
        
...{
            
get
            
...{
                
return Convert.ToString(this["Name"]);
            }

            
set
            
...{
                
this["Name"= value;
            }

        }


        
/**//// <summary>
        
/// 
        
/// </summary>

        [ConfigurationProperty("Size")]
        
public double Size
        
...{
            
get
            
...{
                
return Convert.ToDouble(this["Size"]);
            }

            
set
            
...{
                
this["Size"= value;
            }

        }


        
/**//// <summary>
        
/// 
        
/// </summary>

        [ConfigurationProperty("Style")]
        
public int Style
        
...{
            
get
            
...{
                
return Convert.ToInt32(this["Style"]);
            }

            
set
            
...{
                
this["Style"= value;
            }

        }


        
/**//// <summary>
        
/// 
        
/// </summary>
        
/// <returns></returns>

        public override string ToString()
        
...{
            StringBuilder sb 
= new StringBuilder();
            sb.AppendFormat(
"Name={0}; Size={1}; Style={2}", Name.ToString(), Size.ToString(), Style.ToString());
            
return sb.ToString();
        }

    }

}

 

App.config 

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  
<configSections>
    
<section name="EditorSettings" type="Demo003.EditorFontData, Demo003, Version=1.1.0.0, Culture=neutral, PublicKeyToken=null" />
  
</configSections>
  
<EditorSettings Name="Verdana" Size="24" Style="2" />
</configuration>

 

Form1.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Configuration;

namespace Demo003
...{
    
/**//// <summary>
    
/// 
    
/// </summary>

    public partial class Form1 : Form
    
...{
        
/**//// <summary>
        
/// 
        
/// </summary>

        public Form1()
        
...{
            InitializeComponent();
        }


        
/**//// <summary>
        
/// 
        
/// </summary>
        
/// <param name="sender"></param>
        
/// <param name="e"></param>

        private void button1_Click(object sender, EventArgs e)
        
...{
            
try
            
...{
                EditorFontData aa 
= ConfigurationManager.GetSection("EditorSettings"as EditorFontData;
                MessageBox.Show(aa.ToString());
            }

            
catch (Exception Err)
            
...{
                MessageBox.Show(Err.Message);
            }

        }


        
/**//// <summary>
        
/// 
        
/// </summary>
        
/// <param name="sender"></param>
        
/// <param name="e"></param>

        private void button2_Click(object sender, EventArgs e)
        
...{
            FontDialog fd 
= new FontDialog();
            EditorFontData aa 
= new EditorFontData();
            
if (fd.ShowDialog() == DialogResult.OK)
            
...{
                aa.Name 
= fd.Font.Name;
                aa.Size 
= fd.Font.Size;
                aa.Style
=Convert.ToInt32(fd.Font.Style);

                Configuration config 
= ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                config.Sections.Remove(
"EditorSettings");
                config.Sections.Add(
"EditorSettings", aa);
                config.Save();
            }

        }

    }

}
阅读更多
个人分类: 企業管理
想对作者说点什么? 我来说一句

EnterpriseRes

2009年03月04日 3.23MB 下载

迈克菲企业版8.8

2012年01月14日 33.95MB 下载

没有更多推荐了,返回首页

不良信息举报

企業類庫之Configuration-Migration Application Block(一)

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭