ブラウザのアドレスバーのURLや、リンクをドラッグドロップして、URLを取得する方法です。
たとえば、フォームに、テキストボックを一つ用意して、DragDropイベントと、DragEnterイベントを追加しておいて、以下のコードをいれる。
namespace WindowsFormsApplication1
{
public partial class Form_Main : Form
{
public Form_Main()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.textBox1.AllowDrop = true;
}
private void textBox1_DragDrop(object sender, DragEventArgs e)
{
string url = e.Data.GetData(DataFormats.Text).ToString();
this.textBox1.Text += url + "\r\n";
}
private void textBox1_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent("UniformResourceLocator") ||
e.Data.GetDataPresent("UniformResourceLocatorW"))
{
e.Effect = DragDropEffects.Copy;
}
}
}
}