protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (string.IsNullOrEmpty(this.initSettingsFile)) { this.document = null; } else if (File.Exists(this.initSettingsFile)) { try { document = ClickOnceConfigFile.NewDocument(this.initSettingsFile); } catch (Exception ex) { MessageBox.Show(this, "加载失败," + ex.Message, "提示"); } } else { MessageBox.Show(this, "指定的文件不存在。", "提示"); this.document = null; } UpdateUiFromDocument(document); UpdateUI(); }
/// <summary> /// 新建配置文件。 /// </summary> void NewOptionsFile() { SaveFileDialog sfd = new SaveFileDialog(); sfd.Title = "新建配置文件"; sfd.Filter = "ClickOnce 发布配置文件(*.xml)|*.xml|C# 项目文件(*.csproj)|*.csproj"; if (sfd.ShowDialog(this) == DialogResult.OK) { try { document = ClickOnceConfigFile.NewDocument(sfd.FileName); UpdateUiFromDocument(document); } catch (Exception ex) { MessageBox.Show(this, "加载失败," + ex.Message, "提示"); return; } } UpdateUI(); }