|
1金钱
confighelper类用的是站长发出来的:
namespace DotNet.Utilities.配置文件操作类
{
public class ConfigHelper_sufei
{
/// <summary>
/// 根据Key取Value值
/// </summary>
/// <param name="key"></param>
public static string GetValue(string key)
{
return ConfigurationManager.AppSettings[key].ToString().Trim();
}
/// <summary>
/// 根据Key修改Value
/// </summary>
/// <param name="key">要修改的Key</param>
/// <param name="value">要修改为的值</param>
public static void SetValue(string key, string value)
{
ConfigurationManager.AppSettings.Set(key, value);
}
/// <summary>
/// 添加新的Key ,Value键值对
/// </summary>
/// <param name="key">Key</param>
/// <param name="value">Value</param>
public static void Add(string key, string value)
{
ConfigurationManager.AppSettings.Add(key, value);
}
/// <summary>
/// 根据Key删除项
/// </summary>
/// <param name="key">Key</param>
public static void Remove(string key)
{
ConfigurationManager.AppSettings.Remove(key);
}
}
}
=============================================================================
我的app.config里面是这样写的:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="ThreadCount" value=""/>
<add key="PingTaiUser" value=""/>
<add key="PingTaiPass" value=""/>
</appSettings>
</configuration>
===============================================
我引用后。在一个编辑框文本被改变的事件中,这样写:
private void textBox_ThreadCount_TextChanged(object sender, EventArgs e)
{
DotNet.Utilities.配置文件操作类.ConfigHelper_sufei.SetValue("ThreadCount", textBox_ThreadCount.Text);
}
=================================================================
然后在加载窗体的时候,读取配置文件中的值,是空的。我看app.config文件也没有被修改。
textBox_ThreadCount.Text = DotNet.Utilities.配置文件操作类.ConfigHelper_sufei.GetValue("ThreadCount");
熟悉的大侠,麻烦说说问题出在哪里呢。谢谢。
|
|