[Mono-list] Enable/disable Paste menu item

Andreia Gaita shana.ufie at gmail.com
Sun Jun 24 11:20:03 EDT 2007


There is a Clipboard class available in the framework, and it just so
happens to have a nice Clipboard.ContainsData() method which you can,
for instance, use to check when showing the menu.

andreia

On 6/18/07, Andrus <kobruleht2 at hot.ee> wrote:
> I need to automatically enable/disable Paste menu item in MONO .NET 2
> Winform Edit menu.
>
> http://www.yoda.arachsys.com/csharp/faq/#clipboard  explains how to
> implement this using p/invoke.
>
> How to implement this functionality in MONO WinForms in Linux ?
>
> Andrus.
>
>
> http://www.yoda.arachsys.com/csharp/faq/#clipboard contains:
>
>
> How can I monitor changes to the Clipboard contents (e.g. to enable/disable
> items on the Edit menu, depending on whether there is something to paste)?
>
> Import the SetClipboardViewer API function, and call it in your
> initialisation code, passing the handle of your form. The form will then
> receive WM_DRAWCLIPBOARD messages, which you can handle in WndProc.
>
> using System.Runtime.InteropServices;
> ...
> [DllImport("user32.dll")]
> public static extern int SetClipboardViewer(int hWnd);
> private const int WM_DRAWCLIPBOARD = 776;
>
> // ... somewhere in initialisation code ...
> SetClipboardViewer(this.Handle.ToInt32());
>
> protected override void WndProc(ref Message m)
> {
>   // Process the message normally
>   base.WndProc(ref m);
>
>   if (m.Msg == WM_DRAWCLIPBOARD)
>   {
>      // ... respond to Clipboard changes ...
>   }
> }
>
> _______________________________________________
> Mono-list maillist  -  Mono-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list
>


More information about the Mono-list mailing list