c# - 为什么按回车键不会触发我的 Gtk.Entry 中的 KeyPressEvent?

标签 c# gtk gtk#

我有这样的代码:

    ...

    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/

相关文章:

c# - 向接口(interface)/实现添加事件

c# - 动态编译 LINQ 查询以验证字典值

gtk - 如何禁用/禁用某些GtkMenu项

c - 将指针数组传递给 GTK 相关函数

c# - 绘图区中的 GTK# 鼠标事件

c# - 在 Gtk/Gtk 中绘制图表#

c# - 带窗口句柄的 .net 视频记录

c# - 在 ASP Net.Core 2.2 中使用自动属性扩展 AnchorTagHelper

c++ - gtkmm - 多窗口/弹出窗口

c# - 如何将 SQLite 数据库中的数据显示到 GTK# TreeView 中?