C#中有两个richTextBox1、richTextBox2,要求richTextBox1的内容可以拖放到richTextBox2里面,反向则不行这个功能如何实现啊?
单个richTextBox里面的拖放如下:设置AllowDrop =true;
this.richTextBox1.AllowDrop = true;
添加事件:
this.richTextBox1.DragDrop += new System.Windows.Forms.DragEventHandler(this.richTextBox1_DragEnter);
this.richTextBox1.DragEnter += new System.Windows.Forms.DragEventHandler(richTextBox1_DragEnter);
添加事件的方法:
//实现输入控件的输入内容可以拖动功能。模式为移动
private void richTextBox1_DragEnter(object sender,System.Windows.Forms.DragEventArgs e)
{
if (((DragEventArgs)e).Data.GetDataPresent(DataFormats.Rtf))
((DragEventArgs)e).Effect = DragDropEffects.Move;
else
((DragEventArgs)e).Effect = DragDropEffects.None;
}
控件间的拖放应该如何解决呢? --------------------编程问答-------------------- up --------------------编程问答-------------------- 替lz顶,我也想知道 --------------------编程问答-------------------- 在两个richTextBox拖放“Text”文档时可以正常工作,但一换到DataFormats.Rtf格式时就不能正常了,不知道是为什么。
下面是我的代码:把它们的AllowDrop值设成True
this.richTextBox1.DragDrop += new System.Windows.Forms.DragEventHandler(this.richTextBox1_DragDrop);--------------------编程问答-------------------- up --------------------编程问答-------------------- up --------------------编程问答-------------------- 顶一下
this.richTextBox1.DragEnter += new System.Windows.Forms.DragEventHandler(this.richTextBox1_DragEnter);
...
this.richTextBox2.MouseDown += new System.Windows.Forms.MouseEventHandler(this.richTextBox2_MouseDown);
private void richTextBox1_DragEnter(object sender, System.Windows.Forms.DragEventArgs e)
{
if(e.Data.GetDataPresent("Text"))
e.Effect = DragDropEffects.Move;
}
private void richTextBox1_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
{
e.Effect = DragDropEffects.Move;
}
private void richTextBox2_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
this.richTextBox2.DoDragDrop(this.richTextBox2.SelectedText,DragDropEffects.Move);
}
补充:.NET技术 , C#