【问题标题】:How I can add signals to an array of toolbuttons on a toolbar? mono gtk#如何将信号添加到工具栏上的工具按钮数组?单声道gtk#
【发布时间】:2015-09-25 05:24:11
【问题描述】:

我用这段代码在工具栏上创建了一组按钮

ToolButton [] botones = new ToolButton[3];

    for (int y = 0; y < botones.Length; y++) 
    {
        botones [y] = new ToolButton (Stock.Add);
        botones [y].Label = "menu" + y;
        toolbar1.Insert(botones [y],toolbar1.NItems);


    }
    ShowAll ();

如何将信号添加到每个按钮,所以当我单击时,我会在工具栏中获得每个按钮的标签?

【问题讨论】:

    标签: mono gtk monodevelop gtk#


    【解决方案1】:

    为每个工具按钮的 Clicked 事件添加一个处理程序。

    botones [y].Clicked += (o, args) => {
        ToolButton b = o as ToolButton;
        if (b != null)
            Console.WriteLine ("{0} was press", b.Label);
    };
    

    我也尝试了 ButtonPressEvent 和 ButtonReleaseEvent,但单击工具按钮时都没有抛出。

    【讨论】:

    • ButtonPressEvent 和 ButtonReleaseEvent 是低级输入事件。除非您正在对 GtkDrawingArea 等进行自定义输入处理,否则您不想关注它们。点击这里是正确的事件。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多