开发者

Check Clipboard for Copied texts

I want to add an Cut/Copy/Paste ContextMenuStrip in a RichTextBox, but the problem is, I want to enable or disable the Paste button with respect to the current condition of the windows clipboard.. I mean, if any text开发者_StackOverflow社区 is copied already, then that button should be Enabled, otherwise disabled.

Any idea how I can accomplish that?


You can use Clipboard.ContainsText that you check when the context menu is opened


A note about the ContainsText (Clipboard.HasFormat(CF_TEXT) for Delphi) function... This is definitely the only good solution. Some apps actually go the next step and paste the clipboard text into a buffer for inspection - to see if it contains something that they're looking for, such as an URL (download "helpers" and music apps like to do this), or something else that they recognize such as an XML scrap, text that would represent a control in an IDE (Delphi used to do this), etc.. This is BAD NEWS, as you cannot paste clipboard contents without causing unintended side-effects, such as triggering a WM_RenderFormat message to clipboard viewers.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜