[C#] FileDropTextBox Class

AceInfinity

Emeritus, Contributor
Joined
Feb 21, 2012
Posts
1,728
Location
Canada
Code:
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;
	}
}

I thought this was a cool idea that I came up with so i'll share it with the rest of you :)

Preview:
sOZIh.gif


This is something I've specifically written for implementation in AutoBSA++, but perhaps someone else will find this useful too!
 

Has Sysnative Forums helped you? Please consider donating to help us support the site!

Back
Top