How to detect key press on Xamarin.Mac NSTexField?

帅比萌擦擦* 提交于 2021-01-29 03:10:16

问题


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,


回答1:


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!");
        }
    }
}


来源:https://stackoverflow.com/questions/16582967/how-to-detect-key-press-on-xamarin-mac-nstexfield

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