문제

I am trying to detect when a user presses enter while editing a single line NSTextField, so as to submit the data they've entered.

There doesn't appear to be any events on NSTextField which would be useful,

도움이 되었습니까?

해결책

You can subclass NSTextField and override the keyUp method:

[Register("CustomTextField")]
private class CustomTextField : MonoMac.AppKit.NSTextField
{
    public CustomTextField(IntPtr handle) : base(handle)
    {

    }

    public override void KeyUp (NSEvent theEvent)
    {
        if (theEvent.KeyCode == 36) {
            Console.WriteLine ("You pressed enter!");
        }
    }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top