SimulationEditor.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using DevExpress.XtraEditors;
  2. using System;
  3. using System.IO;
  4. using System.Windows.Forms;
  5. namespace XzXdDw.App.EditForms
  6. {
  7. public partial class SimulationEditor : DevExpress.XtraEditors.XtraForm
  8. {
  9. public string SimulationFile;
  10. public SimulationEditor()
  11. {
  12. InitializeComponent();
  13. this.Text = "仿真文件选择";
  14. this.StartPosition = FormStartPosition.CenterParent;
  15. }
  16. private void btnCancel_Click(object sender, EventArgs e)
  17. {
  18. this.DialogResult = DialogResult.Cancel;
  19. }
  20. private void btnOk_Click(object sender, EventArgs e)
  21. {
  22. var file = btnFile.Text;
  23. if (string.IsNullOrEmpty(file))
  24. {
  25. XtraMessageBox.Show("仿真文件不能为空!");
  26. return;
  27. }
  28. if (!File.Exists(file))
  29. {
  30. XtraMessageBox.Show($"仿真文件{file}不存在!");
  31. return;
  32. }
  33. SimulationFile = file;
  34. this.DialogResult = DialogResult.OK;
  35. }
  36. private void btnFile_Click(object sender, EventArgs e)
  37. {
  38. OpenFileDialog openFileDialog = new OpenFileDialog();
  39. openFileDialog.InitialDirectory = "c:\\";
  40. openFileDialog.Filter = "数据文件|*.dat";
  41. openFileDialog.RestoreDirectory = false;
  42. openFileDialog.FilterIndex = 1;
  43. if (openFileDialog.ShowDialog() == DialogResult.OK)
  44. {
  45. btnFile.Text = openFileDialog.FileName;
  46. }
  47. }
  48. private void btnFile_DragDrop(object sender, DragEventArgs e)
  49. {
  50. var files = ((System.Array)e.Data.GetData(DataFormats.FileDrop));
  51. if (files.Length > 0)
  52. {
  53. btnFile.Text = files.GetValue(0).ToString();
  54. }
  55. }
  56. private void btnFile_DragEnter(object sender, DragEventArgs e)
  57. {
  58. if (e.Data.GetDataPresent(DataFormats.FileDrop))
  59. {
  60. var files = ((System.Array)e.Data.GetData(DataFormats.FileDrop));
  61. if (files.Length == 0)
  62. {
  63. e.Effect = DragDropEffects.None;
  64. return;
  65. }
  66. string file = files.GetValue(0).ToString();
  67. var extension = Path.GetExtension(file);
  68. if (File.Exists(file) && extension.ToUpper() == ".dat".ToUpper())
  69. {
  70. e.Effect = DragDropEffects.Link;
  71. }
  72. }
  73. else
  74. {
  75. e.Effect = DragDropEffects.None;
  76. }
  77. }
  78. }
  79. }