Take the 2-minute tour ×

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?

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

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.

share|improve this answer
Awesome -- this approach will work! Thanks! BTW -- I've followed your blog for quite some time! Thanks! –  Dustin Sep 18 '08 at 17:03
add comment

Your Answer


