使用.net RichTextEdit,但过滤数据类型?
.NET 中的 RichTextEdit
控件完成了我的应用程序需要完成的 99% 的工作,除了一些小事情:
- 我想禁止将图像粘贴/拖动到控件中
- 当粘贴/拖动文本时到控件中,我想将其样式重置为控件的默认样式
据我所知,微软尚未在此控件上提供任何类型的“无图像”属性供您使用,这将是理想的。
我的想法是,我可以响应“textChanged
”事件,然后在渲染到屏幕之前删除图像和/或重置文本样式。 当然,这完全是一种黑客行为。 一方面,用户的拖放鼠标图标将表明图像是可放置的,但实际上却不可放置。
长话短说,有没有办法设置过滤器来限制 RichTextEdit
控件可以通过复制粘贴和拖放导入哪些类型的数据类型?
The RichTextEdit
control in .NET does 99% of what I need to do for my application, except for a few little things:
- I want to disallow pasting/dragging images into the control
- When text is pasted/dragged into the control, I want to reset its style to the control's default
As far as I can work out, Microsoft hasn't provided any type of "no images" property on this control that you can use, which would be ideal.
My thought was that I could respond to the "textChanged
" event then remove the image and/or reset the text style before it gets rendered to the screen. Of course this would be a total hack. For one thing, the user's drag&drop mouse icon would indicate that images are droppable and they really aren't.
To make a long question short, is there a way to set a filter on what type of data types a RichTextEdit
control can import via Copy&Paste and Drag&Drop?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个有可能; 但是,您必须离开 .NET RichTextBox 接口的限制才能执行此操作,因为所需的回调位于 IRichEditOleCallback COM 接口。
为了让您了解 ATL C++ 中涉及的内容(尽管不能保证这会起作用,并且您必须对其进行调整以适应您使用任何语言创建的普通 Ol'COM 对象):
This is possible; however, you'll have to leave the confines of the .NET RichTextBox interface to do it, as the callback needed lives in the IRichEditOleCallback COM interface.
To give you an idea of what's involved, in ATL C++ (no guarantees that this will work though, and you'll have to adapt it to however you create a Plain Ol' COM Object in whatever language you're working in):