将windows应用程序配置文件的<appSettings>节中的值映射到控件的属性,
在控件属性更改后,怎么保存到配置文件中啊?
我以前用修改XML文件保存,这样太啰唆了,有没有更好的办法?
在控件属性更改后,怎么保存到配置文件中啊?
我以前用修改XML文件保存,这样太啰唆了,有没有更好的办法?
解决方案 »
- [求助]如何用c#获取另一个应用程序文本框中的值
- 求助!C#如何指定路径去访问移动设备
- vs2005帮助问题:安装了vs2005,msdn lib for 2005,帮助不正常,目录窗口无项目,点筛选依据中的项目,即出错退出,求解决方法。
- Textbox 文本框 的数据验证问题,请大家帮忙!。。。
- 分散完了,求救
- 有没有.NET下的序列化工具包?
- 请问一下用过VS2005的朋友,是不是用2005就非要用SQL2005?我的机子为C2.4。256内存,是不是不能装?(目前在线,一会就结贴))
- this.Size为什么变小了?
- iframe 框架的问题
- c#会取代c++吗?
- 怎样将文本文件里的一部分行删除掉,利用StreamReader怎么实现。。急啊...
- ADO.NET菜问。
using System;
using System.Xml;
using System.Windows.Forms;namespace Common
{
/// <summary>
/// 模块名称: 读写系统配置类
/// 编写日期: 2005-12-01
/// </summary>
public class AppConfig
{
public static bool UpdateConfig(string strKey, string strValue)
{
XmlDocument doc = new XmlDocument();
try
{
doc.Load(Application.ExecutablePath + ".config");
XmlNode node = doc.SelectSingleNode(@"//add[@key='" + strKey + "']");
XmlElement ele = (XmlElement)node;
ele.SetAttribute("value", strValue);
doc.Save(Application.ExecutablePath + ".config");
}
catch
{
return false;
}
return true;
}
public AppConfig()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public static string GetConfig(string strKey)
{
//return System.Configuration.ConfigurationManager.AppSettings[strKey];
XmlDocument doc = new XmlDocument();
try
{
doc.Load(Application.ExecutablePath + ".config");
XmlNode node = doc.SelectSingleNode(@"//add[@key='" + strKey + "']");
XmlElement ele = (XmlElement)node;
return ele.GetAttribute("value");
}
catch
{
return string.Empty;
}
}
}
}
学习一下...
Snowdust(雪尘) ( ) 信誉:100 Blog
在运行时修改<appSettings>节点值,然活再用
System.Configuration.ConfigurationSettings.AppSettings["key"]获取值,
结果还是未修改前的值
增加了Settings.setting设置文件,可以对用户级别的配置文件进行直接修改。
http://www.microsoft.com/china/msdn/library/langtool/vcsharp/SettingsCSRL.mspx?mfr=true