开发者

Getting associated text with Ctrl+V using C#

I am u开发者_StackOverflow社区sing a rich text box to enter some variables. I am restricting the user from entering some special characters. But user is able to enter the same values by copying from a notepad and pasting it in text box. How can I restrict the user from doing so?

Thanks, Naresh


Hi to prevent pasting from clipboard in the KeyDown event handler you can check if Ctrl was pressed and if so you set e.handled to true. this should work :)


You can write your own filter method/class. So check sometimes (either timer, event, whatever) for bad charackters and garbage them!


Here is a good SO question that i think addresses this:

Intercept paste event on HtmlEditor WinForms

You have to sub-class it and stop the paste message from getting farther down, by overriding WndPrc. Then, call your own function to handle the paste.

I think there is an easier way to locate the paste message, though. Ignore his code for inserting the content, since that doesn't apply to an RTF.


I'd look at using the TextChanged event, in the handler you can unhook the handler, modify the text, and rehook the handler (to avoid it calling itself infinetly)

That should also work for users right clicking and selecting paste from the context menu, im not sure that would trigger the KeyDown event.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜