コード例 #1
0
        private void 導出預設文件OToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog ExportSettingDialog = new OpenFileDialog();

            ExportSettingDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\弹幕姬\\Plugins\\";
            ExportSettingDialog.FileName         = "setting.xml";
            ExportSettingDialog.Filter           = "程式設置檔文件 (*.xml)|*.xml|所有文件 (*.*)|*.*";
            ExportSettingDialog.FilterIndex      = 1;
            ExportSettingDialog.RestoreDirectory = true;

            if (ExportSettingDialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if (DisplaySet == null)
                    {
                        return;
                    }
                    string filename             = ExportSettingDialog.FileName;
                    System.IO.FileStream stream = new System.IO.FileStream
                                                      (filename, System.IO.FileMode.Create);
                    DisplaySet.WriteXml(stream);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("導出設置檔失敗,原始錯誤檔如下: \n" + ex.Message);
                }
            }
        }
コード例 #2
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (DisplaySet == null)
     {
         MessageBox.Show("當前數據内容爲空,無法保存!", "保存錯誤", MessageBoxButtons.OK, MessageBoxIcon.Information);
         return;
     }
     try
     {
         string filename             = setting_file_path;
         System.IO.FileStream stream = new System.IO.FileStream
                                           (filename, System.IO.FileMode.Create);
         DisplaySet.WriteXml(stream);
         this.DialogResult = DialogResult.OK;
         this.Close();
     }
     catch (Exception ex)
     {
         MessageBox.Show("導出設置檔失敗,原始錯誤檔如下: \n" + ex.Message);
     }
 }