日期:2014-05-18 浏览次数:20782 次
using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Text; using System.Windows.Forms; using System.IO; namespace Common { public partial class UserControl1 : UserControl { public UserControl1() { InitializeComponent(); } private void UserControl1_DragEnter(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop))//表示此时为文件拖拽 e.Effect = DragDropEffects.Copy; } private void UserControl1_DragDrop(object sender, DragEventArgs e) { string fileName = ((string[])e.Data.GetData(DataFormats.FileDrop))[0]; try { Image image = Image.FromFile(fileName); this.pictureBox1.Image = image; } catch { MessageBox.Show("当前拖拽的文件不是有效的图像文件"); return; } } } }
------解决方案--------------------
事件过滤,
由这两个事件,触发U控件的事件.
------解决方案--------------------
楼主再说明白一点吧。
------解决方案--------------------
[Quote=引用:]
using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Text; using System.Windows.Forms; using System.IO; namespace Common { public partial class UserControl1 : UserControl { public UserControl1() { InitializeComponent(); } private void UserControl1_DragEnter(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop))//表示此时为文件拖拽 e.Effect = DragDropEffects.Copy; } private void UserControl1_DragDrop(object sender, DragEventArgs e) { string fileName = ((string[])e.Data.GetData(DataFormats.FileDrop))[0]; try { Image image = Image.FromFile(fileName); this.pictureBox1.Image = image; } catch { MessageBox.Show("当前拖拽的文件不是有效的图像文件"); return; } } } }