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$
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$
  • $\begingroup$ Very nice. (+1) Holding out for more just in case. $\endgroup$ – Edmund Mar 3 '17 at 19:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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