简体   繁体   中英

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 is copied already, then that button should be Enabled, otherwise disabled.

Any idea how I can accomplish that?

您可以使用在打开上下文菜单时检查的Clipboard.ContainsText

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM