如何保存用户的设置,既FORM 的大小,TABLE 的大小.急急急(20分,回答的都有分) 大概的情况是用splitcontainer 把桌面分成两部分,当用户自己设置两部分的大小后,下次重起时出现的是上次的大小.要求写到 CONFIG 文件中. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 写xml文件应该不难啊,自己去试试应该没什么问题。 可是头让写到CONFIG 文件中,郁闷 楼上的兄弟说得对,这个问题这么简单把form的Piont,Height,Width读出来,然后持久化就可以了,比如放在xml文件中,或者放在ini文件中,或者放在数据库中,用户打开时在show的时候加载就可以了。 继续等,谢谢Snowdust(雪尘)和guitar__(),各得10分.给代码的加50分 XML文件:<?xml version="1.0" encoding="utf-8" ?><config> <Width>200</Width> <Height>200</Height></config>读取及写入:XmlDocument doc = new XmlDocument();string fileName = Application.StartupPath + "//Config.xml";doc.Load(fileName);int width = Convert.ToInt32(doc.SelectSingleNode("//Width").ChildNodes[0].Value);int height = Convert.ToInt32(doc.SelectSingleNode("//Height").ChildNodes[0].Value);doc.SelectSingleNode("//Width").ChildNodes[0].Value = "400";doc.SelectSingleNode("//Height").ChildNodes[0].Value = "300";doc.Save(fileName); 谢谢Snowdust(雪尘),但是老板要求写到USER.CONFIG文件中,这是一个PROJECT 的一部分.为了协调统一,要用CONFIGURATIONMANAGER.APPSETTINGS的命令写,现在我一直搞不懂怎样使定义的KEY 与我要改写的FORM 连在一起. 呵呵,在App.Config中更简单。明天给你代码,今天太晚了。 using System;using System.Xml;using System.Windows.Forms;namespace Common{ /// <summary> /// 模块名称: 读写系统配置类 /// 作 者: Snowdust /// 编写日期: 2005-12-01 /// </summary> public class AppConfig { private 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; } } public static bool SetConfig(string strKey, string strValue) { return AppConfig.UpdateConfig(strKey, strValue); } }} 小弟我正在写一个WPF项目,遇到一个难题,求各位大神指导…… 远程教学系统如何开发 如果在 IIS 中没有将虚拟目录配置为应用程序,则可能导致此错误 数据库查询问题 在C#中通过SQL语句删除一行数据 关于System.Runtime.InteropServices.COMException 库没有注册的问题 请大家做几道选择道. c#大量数据常驻内存问题 C#中如何编程实现浏览pdf文件? 技术讨论:做ERP CS与BS架构的优劣(100分给有价值答案,100分给参与讨论的兄弟) 关于数据更新问题。长学问 求助 正则表达式的问题.只能输入1至12的数字呢?别的都不行
把form的Piont,Height,Width读出来,
然后持久化就可以了,比如放在xml文件中,
或者放在ini文件中,或者放在数据库中,
用户打开时在show的时候加载就可以了。
<?xml version="1.0" encoding="utf-8" ?>
<config>
<Width>200</Width>
<Height>200</Height>
</config>读取及写入:
XmlDocument doc = new XmlDocument();
string fileName = Application.StartupPath + "//Config.xml";
doc.Load(fileName);
int width = Convert.ToInt32(doc.SelectSingleNode("//Width").ChildNodes[0].Value);
int height = Convert.ToInt32(doc.SelectSingleNode("//Height").ChildNodes[0].Value);
doc.SelectSingleNode("//Width").ChildNodes[0].Value = "400";
doc.SelectSingleNode("//Height").ChildNodes[0].Value = "300";
doc.Save(fileName);
using System.Xml;
using System.Windows.Forms;namespace Common
{
/// <summary>
/// 模块名称: 读写系统配置类
/// 作 者: Snowdust
/// 编写日期: 2005-12-01
/// </summary>
public class AppConfig
{
private 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;
}
}
public static bool SetConfig(string strKey, string strValue)
{
return AppConfig.UpdateConfig(strKey, strValue);
}
}
}