문제

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.

도움이 되었습니까?

해결책

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]);
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top