RichEdit not respecting PlainText with pasted content

元气小坏坏 提交于 2019-12-05 01:40:35

问题


I create a new application, drop on a TRichedit and set the PlainText property to true. I then run the application and paste some rich formatted text into the RichEdit.

I would expect it to display as plain text however it shows the content with the formatting.

Anyone know how to use a TRichedit just as plain text (and not using a memo :))


回答1:


You'll need to do the paste manually ensuring that the formatting is ignored.

if Clipboard.HasFormat(CF_TEXT) then
  RichEdit.SelText := Clipboard.AsText; 

Run this code from a message handler for WM_PASTE.

I currently do not know how to intercept the CTRL+V keypress and replace it with this code. The WM_PASTE message is not sent to rich edit controls.


As Cody suggests in the comment, one solution is as follows:

  • Make sure that all the text in the edit control is marked as protected.
  • Subclass TRichEdit and override CNNotify.
  • Handle the EN_PROTECTED message, and if msg=WM_PASTE then use the paste as text code above and return 1 from the message handler to indicate that the requested operation (a rich paste) is rejected.


来源:https://stackoverflow.com/questions/6038998/richedit-not-respecting-plaintext-with-pasted-content

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!