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]);
}