我有这样的代码:
...
entry.KeyPressEvent += EntryKeyPressEvent;
...
}
void EntryKeyPressEvent(object o, KeyPressEventArgs args)
{
Console.WriteLine("DEBUG: KeyValue: " + args.Event.KeyValue);
...
}
EntryKeyPressEvent 在按下大多数键时调用,但不按下返回键。这是为什么?
编辑:按下大多数键时实际上不会调用它。有些人称之为(例如向上箭头、向下箭头、转义),但大多数人不这么称呼(例如任何字母键、回车)。
作为引用,我正在尝试移植如下所示的 PyGTK 代码:
...
entry.connect('key_press_event', self.entry_key_pressed)
...
def entry_key_pressed(self, widget, event):
...
最佳答案
我能够从 this mailing list thread 中找出答案。我所要做的就是将 ConnectBefore
属性应用于处理程序方法:
[ConnectBefore]
void EntryKeyPressEvent(object o, KeyPressEventArgs args)
{
Console.WriteLine("DEBUG: KeyValue: " + args.Event.KeyValue);
...
}
关于c# - 为什么按回车键不会触发我的 Gtk.Entry 中的 KeyPressEvent?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1698437/