avatar

professional geek ramblings
est. 2003
About

Drag and Drop Urls in Windows Forms

So I wanted to allow for this, right? What if I find something on the net that just begs me to post it, and I want to use the url as the source for my post? Well, it's insanely easy...but you still have to wire it up a little bit. From the article I found (using google, of course), I changed the source code to this:


1 private void txtUrl_DragEnter(object sender, System.Windows.Forms.DragEventArgs e) {
2 if(e.Data.GetDataPresent(DataFormats.Text)){
3 e.Effect = DragDropEffects.All;
4 }
5 }
6
7 private void txtUrl_DragDrop(object sender, System.Windows.Forms.DragEventArgs e) {
8 this.txtUrl.Text = e.Data.GetData(DataFormats.Text).ToString();
9 }

where txtUrl is the url I want to use as a source for my post. Set AllowDrop = true in the designer, and you're good to go.