private void OnFIleMenuExportClick(object sender, EventArgs e) { var result = exportHostDialog.ShowDialog(this); if (result != DialogResult.Yes && result != DialogResult.OK) { return; } try { using var stream = exportHostDialog.OpenFile(); using var writer = new StreamWriter(stream, Encoding.UTF8); writer.Write(JsonConvert.SerializeObject(Settings.Default.hosts)); MessageBox.Show( string.Format(Resources.StrExportFileAt, exportHostDialog.FileName), Resources.StrExportSuccess, MessageBoxButtons.OK, MessageBoxIcon.Information ); } catch (Exception exception) { LogForm.Error("导出文件出现错误:" + exception.Message); MessageBox.Show( exception.Message, Resources.StrExportFileError, MessageBoxButtons.OK, MessageBoxIcon.Error ); } }