NSPasteboard and MonoMac

狂风中的少年 提交于 2019-12-11 12:04:49

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!