3
$\begingroup$

I have followed the instructions for creating a blank .Net form and it works.

Needs["NETLink`"]
InstallNET[];
myform = NETNew["System.Windows.Forms.Form"];
ShowNETWindow[myform];
(* Don't forget to release it later *)
ReleaseNETObject[myform];

However, I cannot get a reference to "System.Windows.Clipboard".

clipboard = NETNew["System.Windows.Clipboard"]

NET::netexcptn: A .NET exception occurred: System.TypeLoadException: Type System.Windows.Clipboard not found. at Wolfram.NETLink.TypeLoader.GetType(String typeName, String assemblyName, Boolean throwOnError) at Wolfram.NETLink.Internal.CallPacketHandler.loadType1(KernelLinkImpl ml).

What am I missing?

$\endgroup$

1 Answer 1

6
$\begingroup$

First, we must load the PresentationCore assembly to make the type System.Windows.Clipboard available:

Needs["NETLink`"]
InstallNET[];

LoadNETAssembly["PresentationCore"];

Second, System.Windows.Clipboard is a static class so it cannot be instantiated using NETNew. We must import its static members instead:

LoadNETType["System.Windows.Clipboard", AllowShortContext -> False];

Now, we can access the clipboard through static members such as GetText:

CopyToClipboard["hi there"]

System`Windows`Clipboard`GetText[]
(* "hi there" *)
$\endgroup$
1
  • $\begingroup$ Very nice. (+1) Holding out for more just in case. $\endgroup$
    – Edmund
    Commented Mar 3, 2017 at 19:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.