TextBox支持拖拽路径和文件
textbox集成路径和文件的双击选择和拖拽选择
public class TextBoxPath : TextBox
{ public TextBoxPath() : base() { this.DoubleClick += TextBoxPath_DoubleClick; this.DragEnter += TextBoxPath_DragEnter; this.DragDrop += TextBoxPath_DragDrop; } private void TextBoxPath_DragEnter(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Link; else e.Effect = DragDropEffects.None; } private void TextBoxPath_DragDrop(object sender, DragEventArgs e) { string path = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString(); (sender as Control).Text = path; } private void TextBoxPath_DoubleClick(object sender, EventArgs e) { FolderBrowserDialog dialog = new FolderBrowserDialog(); if (dialog.ShowDialog() == DialogResult.OK) { (sender as Control).Text = dialog.SelectedPath; } } }
GarsonZhang www.infnitee.com
版权声明:本文为YES开发框架网发布内容,转载请附上原文出处连接
post YES开发框架