C#写的form程序如何关闭自己重新运行?? C#写的form程序如何关闭自己重新运行???运行后如何获得关闭前的一些选择 比如checkbox是否选没有呢?? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 选项可以保存在settings里。自己重新运行?不晓得。 Application.Restart();在Form_Closing事件中将你要保存的状态写到文件中,然后重新打开时读取文件中的内容 private void ReadConfig() { Properties.Settings.Default.Reload(); this.tbFtpIp.Text = Properties.Settings.Default.ftpServer; this.tbFtpPort.Text = Properties.Settings.Default.ftpPort; this.tbUserName.Text = Properties.Settings.Default.ftpUser; this.tbPassword.Text = Properties.Settings.Default.ftpPassword; this.tbFtpTimer.Text = Properties.Settings.Default.ftpFrequence; this.tbFileType.Text = Properties.Settings.Default.FileType; this.tbLocalDirectory.Text = Properties.Settings.Default.localFilePath; this.tbTimer.Text = Properties.Settings.Default.Frequence; } private void btnSaveFtpConfig_Click(object sender, EventArgs e) { try { SaveConfig("ftpServer", tbFtpIp.Text, false); SaveConfig("ftpPort", tbFtpPort.Text, false); SaveConfig("ftpUser", tbUserName.Text, false); SaveConfig("ftpPassword", tbPassword.Text, false); SaveConfig("ftpFrequence", tbFtpTimer.Text, false); SaveConfig("localFilePath", tbLocalDirectory.Text, false); SaveConfig("FileType", tbFileType.Text, false); SaveConfig("Frequence", tbTimer.Text, true); DialogResult dr=MessageBox.Show("配置信息保存成功,请重新启动应用程序","提示",MessageBoxButtons.YesNo,MessageBoxIcon.Information,MessageBoxDefaultButton.Button1); if (dr == DialogResult.Yes) { Application.ExitThread(); Restart(); } } catch { MessageBox.Show("保存配置信息失败,请确保文件完整"); } } private void SaveConfig(string varient, string value, bool Reload) { // 保存 Applicationi 范围的设置 string configFileName = Application.ExecutablePath + ".config"; System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); doc.Load(configFileName); string configString = "configuration/applicationSettings/ftpTransport.Properties.Settings/setting[@name='" + varient + "']/value"; System.Xml.XmlNode configNode = doc.SelectSingleNode(configString); if (configNode != null) { configNode.InnerText = value; doc.Save(configFileName); if (Reload) { // 刷新应用程序设置,这样下次读取时才能读到最新的值。 Properties.Settings.Default.Reload(); } } } private void Restart() { Thread thtmp = new Thread(new ParameterizedThreadStart(run)); object appName = Application.ExecutablePath; Thread.Sleep(2000); thtmp.Start(appName); } private void run(Object obj) { Process ps = new Process(); ps.StartInfo.FileName = obj.ToString(); ps.Start(); } 楼上的你的函数private void ReadConfig() { Properties.Settings.Default.Reload(); this.tbFtpIp.Text = Properties.Settings.Default.ftpServer; this.tbFtpPort.Text = Properties.Settings.Default.ftpPort; this.tbUserName.Text = Properties.Settings.Default.ftpUser; this.tbPassword.Text = Properties.Settings.Default.ftpPassword; this.tbFtpTimer.Text = Properties.Settings.Default.ftpFrequence; this.tbFileType.Text = Properties.Settings.Default.FileType; this.tbLocalDirectory.Text = Properties.Settings.Default.localFilePath; this.tbTimer.Text = Properties.Settings.Default.Frequence; } 没看见去读取配置文件,是如何从文件里把config取出来的?? Application.Restart(); 真厉害,我每次都是加一个WatchDog程序 如何实现读取word文件,并将每一页以图片的方式发送到客户端? (简单基础)快考试咯 发几道题目 求正确答案 C#问题,高手来啊 采集网页数据,有需要登陆后才查看的页面怎么办?? 主程序关掉~为什么由副程序也关掉了~ 参数和返回值 高手还用Msdn吗? window窗体之间实现的代码 高手帮忙 怎样用按钮触发dataGrid 的某列排序? 求份神龙卡SDK或C#源码 又一个字符串的问题,大家帮忙看一下 一个小问题,如何在C#中动态改变菜单项的状态
在Form_Closing事件中将你要保存的状态写到文件中,然后重新打开时读取文件中的内容
{
Properties.Settings.Default.Reload();
this.tbFtpIp.Text = Properties.Settings.Default.ftpServer;
this.tbFtpPort.Text = Properties.Settings.Default.ftpPort;
this.tbUserName.Text = Properties.Settings.Default.ftpUser;
this.tbPassword.Text = Properties.Settings.Default.ftpPassword;
this.tbFtpTimer.Text = Properties.Settings.Default.ftpFrequence; this.tbFileType.Text = Properties.Settings.Default.FileType;
this.tbLocalDirectory.Text = Properties.Settings.Default.localFilePath;
this.tbTimer.Text = Properties.Settings.Default.Frequence;
}
private void btnSaveFtpConfig_Click(object sender, EventArgs e)
{
try
{
SaveConfig("ftpServer", tbFtpIp.Text, false);
SaveConfig("ftpPort", tbFtpPort.Text, false);
SaveConfig("ftpUser", tbUserName.Text, false);
SaveConfig("ftpPassword", tbPassword.Text, false);
SaveConfig("ftpFrequence", tbFtpTimer.Text, false);
SaveConfig("localFilePath", tbLocalDirectory.Text, false);
SaveConfig("FileType", tbFileType.Text, false);
SaveConfig("Frequence", tbTimer.Text, true);
DialogResult dr=MessageBox.Show("配置信息保存成功,请重新启动应用程序","提示",MessageBoxButtons.YesNo,MessageBoxIcon.Information,MessageBoxDefaultButton.Button1);
if (dr == DialogResult.Yes)
{
Application.ExitThread();
Restart();
}
}
catch
{
MessageBox.Show("保存配置信息失败,请确保文件完整");
}
}
private void SaveConfig(string varient, string value, bool Reload)
{
// 保存 Applicationi 范围的设置
string configFileName = Application.ExecutablePath + ".config";
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.Load(configFileName);
string configString = "configuration/applicationSettings/ftpTransport.Properties.Settings/setting[@name='" + varient + "']/value";
System.Xml.XmlNode configNode = doc.SelectSingleNode(configString);
if (configNode != null)
{
configNode.InnerText = value;
doc.Save(configFileName);
if (Reload)
{
// 刷新应用程序设置,这样下次读取时才能读到最新的值。
Properties.Settings.Default.Reload();
}
} }
private void Restart()
{
Thread thtmp = new Thread(new ParameterizedThreadStart(run));
object appName = Application.ExecutablePath;
Thread.Sleep(2000);
thtmp.Start(appName);
}
private void run(Object obj)
{
Process ps = new Process();
ps.StartInfo.FileName = obj.ToString();
ps.Start();
}
private void ReadConfig()
{
Properties.Settings.Default.Reload();
this.tbFtpIp.Text = Properties.Settings.Default.ftpServer;
this.tbFtpPort.Text = Properties.Settings.Default.ftpPort;
this.tbUserName.Text = Properties.Settings.Default.ftpUser;
this.tbPassword.Text = Properties.Settings.Default.ftpPassword;
this.tbFtpTimer.Text = Properties.Settings.Default.ftpFrequence; this.tbFileType.Text = Properties.Settings.Default.FileType;
this.tbLocalDirectory.Text = Properties.Settings.Default.localFilePath;
this.tbTimer.Text = Properties.Settings.Default.Frequence;
}
没看见去读取配置文件,是如何从文件里把config取出来的??
真厉害,我每次都是加一个WatchDog程序