انتقال مقادیر خاصیت Text دو تکست باکس از طریق Drag & Drop
کد:
private void textBox_DragDrop(object sender, DragEventArgs e)
{
TextBox txt = (TextBox)sender;
txt.Text = (string)e.Data.GetData(DataFormats.Text);
}
private void textBox_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.Text))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void textBox_MouseDown(object sender, MouseEventArgs e)
{
TextBox txt = (TextBox)sender;
txt.SelectAll();
txt.DoDragDrop(txt.Text, DragDropEffects.Copy);
}
private void Form1_Load(object sender, EventArgs e)
{
textBox2.DragDrop += new DragEventHandler(this.textBox_DragDrop);
textBox2.MouseDown += new MouseEventHandler(this.textBox_MouseDown);
textBox2.DragEnter += new DragEventHandler(this.textBox_DragEnter);
textBox1.DragDrop += new DragEventHandler(this.textBox_DragDrop);
textBox1.MouseDown += new MouseEventHandler(this.textBox_MouseDown);
textBox1.DragEnter += new DragEventHandler(this.textBox_DragEnter);
textBox1.AllowDrop = textBox2.AllowDrop = true;
}