CSharp中RichTextBox上的功能缺失(文件拖放)问题 [英] Problem with Feature missing (File Drag Drop) at RichTextBox in CSharp

查看:152
本文介绍了CSharp中RichTextBox上的功能缺失(文件拖放)问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows窗体应用程序中工作,希望将文件拖放到RichTextBox上,并在RichTextBox中显示其内容。虽然使用简单的TextBox来完成此操作没有问题,但是在RichTextBox中我没有这个工作,因为首先在事件的控件属性对话框中缺少必要的两个拖放事件。

我可以找到一个代码并将其放在Form_Load中,但是在RichTextBox中仍然保持File DragDrop仍然不可用。



这是我的不工作代码:它只是在没有发生的情况下不会发生错误。



I work in a Windows Form Application and would like to drag and drop a file on a RichTextBox and display its contents in the RichTextBox. While I have no problem to do this with a simple TextBox, in a RichTextBox I don't get this to work because the necessary two drag drop events are missing in the controls properties dialogbox in events in the first place.
I could find a code and have put it in Form_Load, but in the RichTextBox stays the File DragDrop still unavailable.

That's my not working code: It just doens't function errors where not occuring.

this.richTextBox1.AllowDrop = true;
this.richTextBox1.DragEnter += new System.Windows.Forms.DragEventHandler(this.RichTextBoxDragEnter);
this.richTextBox1.DragDrop += new System.Windows.Forms.DragEventHandler(this.RichTextBoxDragDrop);





关于RichTextBox如何/为何如何/为什么的任何其他想法默认情况下没有DragDrop函数

以及如何添加它们?



Any other ideas on how / why the RichTextBox has no DragDrop functions by default
and how to add them?

推荐答案

它确实:或者至少在我的VS版本中它确实如此!但不是从设计窗口,奇怪的是...

不要忘记,为了让它工作,你需要为你的活动添加代码:



It does: or at least in my version of VS it does! But not from the Design window, strangely...
Don't forget, to get it to work, you need to add code to your events:

txtDetail.AllowDrop = true;
    txtDetail.DragEnter += txtDetail_DragEnter;
    txtDetail.DragDrop += txtDetail_DragDrop;
    }


void txtDetail_DragEnter(object sender, DragEventArgs e)
    {
    e.Effect = DragDropEffects.Copy;
    }
void txtDetail_DragDrop(object sender, DragEventArgs e)
    {
    ...
    }



如果你没有设置效果,那么DragDrop将不起作用。


If you don't set the Effect, then DragDrop will not work.


这篇关于CSharp中RichTextBox上的功能缺失(文件拖放)问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆