拖放只读富文本框 [英] Drag and drop in read only rich text box
问题描述
我正在尝试在 RichTextBox(Windows 通用控件)中实现拖放功能.使用下面显示的代码可以正常工作.但是,当我将 ReadOnly 属性设置为 true 时,不会触发拖放事件.有什么我想念的吗?或者这是正确的行为?请指教.
I am trying implement drag and drop feature in RichTextBox (windows common control). It works fine using the code shown below. However, the drag drop event is not getting triggered when I set the ReadOnly property to true. Is there anything that I am missing? or is that the right behaviour ? Please advice.
private void rtb_dragdrop(object sender, DragEventArgs e)
{
Console.WriteLine("Test");
}
private void rtb_dragenter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Copy;
}
推荐答案
显然,在 RichTextBox 中将 ReadOnly 属性设置为 true 将关闭执行拖放操作的能力.
Obviously, setting the ReadOnly property to true in a RichTextBox will turn off the ability to do Drag and Drop operations.
一个简单的模仿只读 RichTextBox:
A simple hack to mimic a read only RichTextBox:
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
rtb.EnableAutoDragDrop = true;
rtb.KeyDown += new KeyEventHandler(rtb_KeyDown);
}
void rtb_KeyDown(object sender, KeyEventArgs e) {
e.SuppressKeyPress = true;
}
}
现在您的拖放操作应该在 EnabledAutoDragDrop
属性设置为 true 的情况下自动工作.无需处理那些拖拽输入和拖放事件.
Now your Drag and Drop operation should work automatically with the EnabledAutoDragDrop
property set to true. No need to handle those drag enter and drop events.
这篇关于拖放只读富文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!