123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- using DevExpress.XtraEditors;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace ExtensionsDev
- {
- public static class ChooseFileExtension
- {
- public static ButtonEdit UseChooseFile(this ButtonEdit ctrl)
- {
- ctrl.AllowDrop = true;
- ctrl.DragEnter += ctrl_DragEnter;
- ctrl.DragDrop += ctrl_DragDrop;
- ctrl.ButtonClick += Ctrl_ButtonClick;
- return ctrl;
- }
- private static void Ctrl_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
- {
- var ctrl = sender as Control;
- XtraOpenFileDialog xtraOpenFileDialog1 = new XtraOpenFileDialog();
- xtraOpenFileDialog1.Multiselect = false;
- if (xtraOpenFileDialog1.ShowDialog() == DialogResult.OK)
- {
- ctrl.Text = xtraOpenFileDialog1.FileName;
- }
- }
- private static void ctrl_DragEnter(object sender, DragEventArgs e)
- {
- if (e.Data.GetDataPresent(DataFormats.FileDrop))
- {
- e.Effect = DragDropEffects.Link;
- }
- else
- {
- e.Effect = DragDropEffects.None;
- }
- }
- private static void ctrl_DragDrop(object sender, DragEventArgs e)
- {
- var file = ((Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();
- (sender as Control).Text = file;
- }
- }
- }
|