Search code examples
monogtkmonodevelopgtk#

How I can add signals to an array of toolbuttons on a toolbar? mono gtk#


I create a group of buttons on the toolbar, with this code

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 ();

How I can add the signals to each button, so when I cliked, I get the label of each button in the toolbar?


Solution

  • Add a handler to the Clicked event for each of the tool buttons.

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

    I also tried the ButtonPressEvent and ButtonReleaseEvent but neither of those were thrown when the tool button was clicked.