tags:

views:

130

answers:

1

I have a GTK notebook with multiple tabs. Each tab label is a composite container containing, among other things, a button I want to use to close the tab. The button has a handler for the "clicked" signal.

When the signal is called, I get the button widget and "EventArgs" as a parameter.

I need to determine the page number based on the button widget, but myNotebook.PageNum(buttonWidget) always returns -1. I've even tried buttonWidget.Parent which is the HBox which contains the widget.

Any ideas on what I can do or what I am doing wrong?

+3  A: 

One easy work around is to pass the page number to your button's Clicked event as you construct the buttons.

for (int page = 0; page < n; page++){ 
    int the_page = page;
    NotebookPage p = new NotebookPage ();
    ...
    Button b = new Button ("Close page {0}", the_page);
    b.Clicked += delegate { 
        Console.WriteLine ("Page={0}", the_page); 
    };
}

The "the_page" is important, as it is a new variable that will be captured by the delegate.

miguel.de.icaza
Awesome -- this approach will work! Thanks!BTW -- I've followed your blog for quite some time! Thanks!
Dustin