C# 属性.设置-多个表单
我有两种表格:C# 属性.设置-多个表单,c#,.net,.net-4.5,application-settings,properties.settings,C#,.net,.net 4.5,Application Settings,Properties.settings,我有两种表格: MainForm 设置表单 可以想象,MainForm使用诸如Properties.Settings.Default.Path和SettingsForm等值,应该能够在运行时配置这样的值 但不知何故,SettingsForm:Properties.Settings.Default.Save()在应用程序重新启动后立即生效,尽管我正在MainForm:Properties.settings.Default.Reload()中重新加载这些设置 到目前为止,我有: 在MainFor
MainForm
设置表单
MainForm
使用诸如Properties.Settings.Default.Path
和SettingsForm
等值,应该能够在运行时配置这样的值
但不知何故,SettingsForm:Properties.Settings.Default.Save()代码>在应用程序重新启动后立即生效,尽管我正在MainForm:Properties.settings.Default.Reload()中重新加载这些设置代码>
到目前为止,我有:
在MainForm.cs
中:
// Handles "config button click" => display settings form
private void configStatusLabel_Click(object sender, EventArgs e)
{
SettingsForm form = new SettingsForm();
form.FormClosed += new FormClosedEventHandler(form_FormClosed);
form.Show();
}
// Callback triggered on Settings form closing
void form_FormClosed(object sender, FormClosedEventArgs e)
{
Properties.Settings.Default.Reload();
}
// There are another methods called after form_FormClosed is triggered, for example
// StremWriter = new StreamWriter( Properties.Settings.Default.Path)
// Triggered on "Save button click" in Settings form, after changing values
// Example: Properties.Settings.Default.Path = "C:\\file.txt"
private void saveButton_Click(object sender, EventArgs e)
{
Properties.Settings.Default.Save();
Close();
}
和设置Form.cs
:
// Handles "config button click" => display settings form
private void configStatusLabel_Click(object sender, EventArgs e)
{
SettingsForm form = new SettingsForm();
form.FormClosed += new FormClosedEventHandler(form_FormClosed);
form.Show();
}
// Callback triggered on Settings form closing
void form_FormClosed(object sender, FormClosedEventArgs e)
{
Properties.Settings.Default.Reload();
}
// There are another methods called after form_FormClosed is triggered, for example
// StremWriter = new StreamWriter( Properties.Settings.Default.Path)
// Triggered on "Save button click" in Settings form, after changing values
// Example: Properties.Settings.Default.Path = "C:\\file.txt"
private void saveButton_Click(object sender, EventArgs e)
{
Properties.Settings.Default.Save();
Close();
}
我错过了什么我如何实现“随需应变”?
更多关于程序流程的信息
在主窗体中,有几个按钮将触发函数,例如使用Properties.Settings.Default.Path的ReloadLog()
。最后,我将按以下顺序执行函数:
ReloadLog(); // Triggered by the user (several times)
// This reloads contents of log, say C:\\main.log
configStatusLabel_Click(); // User hit "configure button", there are two active forms
// SettingsForm is now displayed too
// At this point ReloadLog() may be called in MainForm many times
// Meanwhile in SettingsForm:
Properties.Settings.Default.Path = PathTextBox.Text;
private void saveButton_Click(object sender, EventArgs e) // User hit save button
{
Properties.Settings.Default.Save();
Close(); // This will trigger form_FormClosed in main form
}
// Now you would expect that following line will open D:\\another.log
ReloadLog();
// But it still uses original config, however when I turn app off and on again, it works
你不需要调用实际使用此“按需更改”设置的方法才能产生任何效果吗?@AustinSalonen当然有很多方法使用这些值,但我认为粘贴它们没有任何意义,如果你认为有帮助的话,我将添加全部50个;)所以你在更改设置后会调用它们吗?这些设置不会在窗体关闭时使用,我在主窗体中有“重新加载日志”按钮,用于重新加载日志文件(文件可通过SettingsForm
配置),用户可以随时点击它。在我关闭并重新打开应用程序之前,它总是使用相同的路径(当我按下按钮时)。我猜这与