123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- using DevExpress.XtraEditors;
- using System;
- using System.IO;
- using System.Windows.Forms;
- namespace XdDw.App.EditForms
- {
- public partial class SimulationEditor : DevExpress.XtraEditors.XtraForm
- {
- public string SimulationFile;
- public SimulationEditor()
- {
- InitializeComponent();
- this.Text = "仿真文件选择";
- this.StartPosition = FormStartPosition.CenterParent;
- }
- public SimulationEditor(string fileName)
- : this()
- {
- btnFile.Text = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, fileName);
- }
- private void btnCancel_Click(object sender, EventArgs e)
- {
- this.DialogResult = DialogResult.Cancel;
- }
- private void btnOk_Click(object sender, EventArgs e)
- {
- var file = btnFile.Text;
- if (string.IsNullOrEmpty(file))
- {
- XtraMessageBox.Show("仿真文件不能为空!");
- return;
- }
- if (!File.Exists(file))
- {
- XtraMessageBox.Show($"仿真文件{file}不存在!");
- return;
- }
- SimulationFile = file;
- this.DialogResult = DialogResult.OK;
- }
- private void btnFile_Click(object sender, EventArgs e)
- {
- OpenFileDialog openFileDialog = new OpenFileDialog();
- openFileDialog.InitialDirectory = "c:\\";
- openFileDialog.Filter = "数据文件|*.dat";
- openFileDialog.RestoreDirectory = false;
- openFileDialog.FilterIndex = 1;
- if (openFileDialog.ShowDialog() == DialogResult.OK)
- {
- btnFile.Text = openFileDialog.FileName;
- }
- }
- private void btnFile_DragDrop(object sender, DragEventArgs e)
- {
- var files = ((System.Array)e.Data.GetData(DataFormats.FileDrop));
- if (files.Length > 0)
- {
- btnFile.Text = files.GetValue(0).ToString();
- }
- }
- private void btnFile_DragEnter(object sender, DragEventArgs e)
- {
- if (e.Data.GetDataPresent(DataFormats.FileDrop))
- {
- var files = ((System.Array)e.Data.GetData(DataFormats.FileDrop));
- if (files.Length == 0)
- {
- e.Effect = DragDropEffects.None;
- return;
- }
- string file = files.GetValue(0).ToString();
- var extension = Path.GetExtension(file);
- if (File.Exists(file) && extension.ToUpper() == ".dat".ToUpper())
- {
- e.Effect = DragDropEffects.Link;
- }
- }
- else
- {
- e.Effect = DragDropEffects.None;
- }
- }
- }
- }
|