资源简介
应用程序中,经常需要保存一些用户的设置,所以就需要把这些设置保存到一个配置文件中,以便随时读取和写入。
这个代码就是用C#写的保存和读取程序运行目录下的XML配置文件的程序,配置文件也会自动生成,很灵活的。
共享给大家,大家可以很方便的调用,然后保存和读取自己的程序设置。

代码片段和文件信息
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace ConfigMgrTest
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private void btnSave_Click(object sender EventArgs e)
{
if (this.txtUserID.Text.Trim().Equals(string.Empty))
{
MessageBox.Show(“请输入用户名“);
this.txtUserID.Focus();
return;
}
if (this.txtPassword.Text.Trim().Equals(string.Empty))
{
MessageBox.Show(“请输入密码“);
this.txtPassword.Focus();
return;
}
//保存
SystemConfig.WriteConfigData(“UserID“ this.txtUserID.Text.Trim());
SystemConfig.WriteConfigData(“Password“ this.txtPassword.Text.Trim());
this.txtUserID.Text = null;
this.txtPassword.Text = null;
MessageBox.Show(“成功保存到配置文件“ + Application.StartupPath + “SystemConfig.xml \n点击读取按钮进行读取!“);
}
private void btnClose_Click(object sender EventArgs e)
{
//读取
this.txtUserID.Text = SystemConfig.GetConfigData(“UserID“ string.Empty);
this.txtPassword.Text = SystemConfig.GetConfigData(“Password“ string.Empty);
}
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 3291 2008-12-20 13:39 ConfigMgrTest\ConfigMgrTest.csproj
文件 168 2008-12-20 13:39 ConfigMgrTest\ConfigMgrTest.csproj.user
文件 1544 2008-12-20 13:43 ConfigMgrTest\MainForm.cs
文件 4897 2008-12-20 13:39 ConfigMgrTest\MainForm.Designer.cs
文件 5814 2008-12-20 13:39 ConfigMgrTest\MainForm.resx
文件 483 2008-12-20 13:32 ConfigMgrTest\Program.cs
文件 1280 2008-12-20 13:32 ConfigMgrTest\Properties\AssemblyInfo.cs
文件 2853 2008-12-20 13:32 ConfigMgrTest\Properties\Resources.Designer.cs
文件 5612 2008-12-20 13:32 ConfigMgrTest\Properties\Resources.resx
文件 1096 2008-12-20 13:32 ConfigMgrTest\Properties\Settings.Designer.cs
文件 249 2008-12-20 13:32 ConfigMgrTest\Properties\Settings.settings
文件 11699 2008-12-20 13:42 ConfigMgrTest\SystemConfig.cs
文件 928 2008-12-20 13:32 ConfigMgrTest.sln
..A..H. 22528 2008-12-20 13:43 ConfigMgrTest.suo
目录 0 2008-12-20 13:32 ConfigMgrTest\Properties
目录 0 2008-12-20 13:43 ConfigMgrTest
----------- --------- ---------- ----- ----
62442 16
相关资源
- C# OCR数字识别实例,采用TessnetOcr,对
- 考试管理系统 - C#源码
- asp.net C#购物车源代码
- C#实时网络流量监听源码
- C#百度地图源码
- Visual C#.2010从入门到精通配套源程序
- C# 软件版本更新
- C#屏幕软键盘源码,可以自己定制界面
- 智慧城市 智能家居 C# 源代码
- c#获取mobile手机的IMEI和IMSI
- C#实现简单QQ聊天程序
- 操作系统 模拟的 欢迎下载 C#版
- C#写的计算机性能监控程序
- 用C#实现邮件发送,有点类似于outlo
- MVC model层代码生成器 C#
- c#小型图书销售系统
- C# Socket Server Client 通讯应用 完整的服
- c# winform 自动登录 百度账户 源代码
- C#编写的16进制计算器
- C#TCP通信协议
- C# 数据表(Dataset)操作 合并 查询一
- C#语音识别系统speechsdk51,SpeechSDK51L
- 数据库备份还原工具1.0 C# 源码
-
[免费]xm
lDocument 节点遍历C# - EQ2008LEDc#开发实例
- DirectX.Capturec# winform 操作摄像头录像附
- c# 实现的最大最小距离方法对鸢尾花
- C#版保龄球记分代码
- C#自定义控件
- 基于c#的实验室设备管理系统621530
评论
共有 条评论