using System;
using System.Drawing;
using System.Windows.Forms;
class FileDropTextBox : TextBox
{
public FileDropTextBox()
{
AllowDrop = true;
}
private string _OldText;
protected override void OnDragEnter(DragEventArgs drgevent)
{
base.OnDragEnter(drgevent);
if (drgevent.Data.GetDataPresent(DataFormats.FileDrop))
{
drgevent.Effect = DragDropEffects.Copy;
this.ForeColor = Color.FromArgb(255, 150, 150, 150);
_OldText = this.Text;
this.Text = ((string[])drgevent.Data.GetData(DataFormats.FileDrop))[0];
}
}
protected override void OnDragDrop(DragEventArgs drgevent)
{
base.OnDragDrop(drgevent);
if (drgevent.Data.GetDataPresent(DataFormats.FileDrop))
this.ForeColor = Color.FromArgb(255, 0, 0, 0);
}
protected override void OnDragLeave(EventArgs e)
{
base.OnDragLeave(e);
this.ForeColor = Color.FromArgb(255, 0, 0, 0);
this.Text = _OldText;
}
}