public class zlcRichtextBox : RichTextBox
{
public zlcRichtextBox()
{}
public delegate void mDrag(object e);
public event mDrag DragDrop;
/// <summary>
/// 拖拽
/// </summary>
/// <param name="drgevent"></param>
protected override void OnDragDrop(DragEventArgs e)
{
base.OnDragDrop (e);
if(this.DragDrop != null)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
System.Array file = (System.Array)e.Data.GetData(DataFormats.FileDrop);
this.DragDrop(file.GetValue(0));
}
}
}
protected override void OnDragEnter(DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
e.Effect = DragDropEffects.Move;
else
e.Effect = DragDropEffects.None;
base.OnDragEnter (e);
}
}
如:
zlcRichtextBox rich = new zlcRichtextBox ()
rich.DragDrop += new zlcRichtextBox.mDrag(richTextBox2_DragDrop);
private void richTextBox2_DragDrop(object e)
{
string FileName = e.ToString();
}