c#标签不拖动:

时间:2013-08-18 23:34:13

标签: c# winforms drag-and-drop

当我尝试将标签拖到富文本框中时,图标仍然被拒绝。我的标签位于面板中,与富文本框分开。如何从标签中获取文本以复制到富文本框中?现在我得到一个带有一条线的圆圈,好像我没有将txtText.AllowDrop设置为true,但我在表格加载时就做到了。

由于

1 个答案:

答案 0 :(得分:1)

好的,我发现RichTextBox没有标准的拖放实现。我有一个名为EnableAutoDragDrop的属性,只需将其设置为true,它将自动处理所有内容。除此之外,您不需要注册任何事件:

richTextBox1.EnableAutoDragDrop = true; //Just this even without AllowDrop = true
//RichTextBox doesn't even have DragOver event exposed, we have to cast it to Control to expose the base DragOver event
((Control)richTextBox1).DragOver += (s, e) => 
{
    e.Effect = DragDropEffects.Copy;
};

如果不注册DragOver事件处理程序,则必须在执行drag-n-drop时使用(按住/按下)Control键。