views:

43

answers:

2

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?

+4  A: 

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

thecoop
A: 

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.

Chris Thornton