问题
I had problems with copy and paste on MonoMac and found Clipboard.GetText() always returns empty string in Mono on Mac which suggested using NSPasteboard
but I can't find any good examples or explanation on how to do so in Mono/C#. I think I understand the Objective-C API but the mapping the C# I find confusing so any help would be great.
回答1:
Here is a simple example of copying and pasting a string:
private static string[] pboardTypes = new string[] { "NSStringPboardType" };
public static void SetText(string text)
{
NSPasteboard.GeneralPasteboard.DeclareTypes(pboardTypes, null);
NSPasteboard.GeneralPasteboard.SetStringForType(text, pboardTypes[0]);
}
public static string GetText()
{
return NSPasteboard.GeneralPasteboard.GetStringForType(pboardTypes[0]);
}
来源:https://stackoverflow.com/questions/17789793/nspasteboard-and-monomac