Profile Picture

NTabControl close button event

Posted By Craig Swearingen 12 Years Ago
Author
Message
Craig Swearingen
Posted 12 Years Ago
View Quick Profile
Supreme Being

Supreme Being (97 reputation)Supreme Being (97 reputation)Supreme Being (97 reputation)Supreme Being (97 reputation)Supreme Being (97 reputation)Supreme Being (97 reputation)Supreme Being (97 reputation)Supreme Being (97 reputation)Supreme Being (97 reputation)

Group: Forum Members
Last Active: 7 Years Ago
Posts: 99, Visits: 654

On my NTabControl I've specified

hasClose = true and showCloseOnEachTab = true

I also have registered to receive a ClosingTab event.

How can I code the ClosingTab event to determine which tab is being closed?

Setting the Cancel parameter to true does stop the closing of the tab but its not clear how to know which tab it is.  I'm on the 11.12.14.12 build.



Oliver Münchow
Posted 12 Years Ago
View Quick Profile
Junior Member

Junior Member (10 reputation)Junior Member (10 reputation)Junior Member (10 reputation)Junior Member (10 reputation)Junior Member (10 reputation)Junior Member (10 reputation)Junior Member (10 reputation)Junior Member (10 reputation)Junior Member (10 reputation)

Group: Forum Members
Last Active: 10 Years Ago
Posts: 10, Visits: 2
Within the event you'll receive a DocumentCancelEventArgs. This event handler has a property "NUIDocument Document" which you can ask for the Text property to determine the name of the document or the Client property to get access to the hosted control.

Craig Swearingen
Posted 12 Years Ago
View Quick Profile
Supreme Being

Supreme Being (97 reputation)Supreme Being (97 reputation)Supreme Being (97 reputation)Supreme Being (97 reputation)Supreme Being (97 reputation)Supreme Being (97 reputation)Supreme Being (97 reputation)Supreme Being (97 reputation)Supreme Being (97 reputation)

Group: Forum Members
Last Active: 7 Years Ago
Posts: 99, Visits: 654

Thanks for trying but the event has these two parameters:

ClosingTab(object sender, System.ComponentModel.CancelEventArgs e)

The CancelEventArgs only has the Handled parameter on it and the sender is the NTabControl.  The NTabControl is on an NForm.  Not a NUIDocument.

Any other ideas?



Oliver Münchow
Posted 12 Years Ago
View Quick Profile
Junior Member

Junior Member (10 reputation)Junior Member (10 reputation)Junior Member (10 reputation)Junior Member (10 reputation)Junior Member (10 reputation)Junior Member (10 reputation)Junior Member (10 reputation)Junior Member (10 reputation)Junior Member (10 reputation)

Group: Forum Members
Last Active: 10 Years Ago
Posts: 10, Visits: 2
Hi Craig,

you're right, i'm currently working with the NDocumentManager, which works quite similar to the NTabControl. This one has the described event.

Nevertheless, while you're within the Closing event you can take a look into the `SelectedTab` property of the NTabControl. It holds the tab that's going to close.

Nevron Support
Posted 12 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)

Group: Forum Members
Last Active: Last Year
Posts: 3,039, Visits: 3,746
Oliver,
If ShowCloseOnEachTab is true you can close a tab even if it's not selected.

There is a workaround to solve this problem.
In ClosingTab event handler you can obtain the NTabStrip control which is the first item in NTabControl.Controls collection:

NTabStrip strip = nTabControl1.Controls[0] as NTabStrip;

Then if strip is not null you can iterate to its Tabs and check whether the CloseButton.State is pressed.
The index of the pressed NTab.CloseButton is the index of the tab page which is about to be closed:

Here is the whole source:

NTabStrip strip = nTabControl1.Controls[0] as NTabStrip;
if (strip == null)
{
   return;
}

for (int i = 0; i < strip.Tabs.Count; i++)
{
   if (strip.Tabs[i].CloseButton.State == InteractiveState.Pressed)
   {
      NTabPage page = nTabControl1.TabPages[i];
      break;
   }
}


Best Regards,
Nevron Support Team



Craig Swearingen
Posted 12 Years Ago
View Quick Profile
Supreme Being

Supreme Being (97 reputation)Supreme Being (97 reputation)Supreme Being (97 reputation)Supreme Being (97 reputation)Supreme Being (97 reputation)Supreme Being (97 reputation)Supreme Being (97 reputation)Supreme Being (97 reputation)Supreme Being (97 reputation)

Group: Forum Members
Last Active: 7 Years Ago
Posts: 99, Visits: 654

Thanks again for trying to help.  The SelectedTab holds the tab that is currently selected (on top).  Since you can close any tab even when its not on top it can't be used for this.

Any other ideas? 

Seems like an NTabControl design fix is needed.  The tab page index should be added to the event or the event should be called on the NTabPage instead of the NTabControl.  Nevron Support, can you add this to a future build?



Craig Swearingen
Posted 12 Years Ago
View Quick Profile
Supreme Being

Supreme Being (97 reputation)Supreme Being (97 reputation)Supreme Being (97 reputation)Supreme Being (97 reputation)Supreme Being (97 reputation)Supreme Being (97 reputation)Supreme Being (97 reputation)Supreme Being (97 reputation)Supreme Being (97 reputation)

Group: Forum Members
Last Active: 7 Years Ago
Posts: 99, Visits: 654

Thanks for the CloseButton state code tip.  I had to make one change to the code you provided but it works for me.

InteractiveState istate = strip.Tabs[i].CloseButton.State;

if ((istate == InteractiveState.Pressed) || (istate == InteractiveState.Hovered))

I had to check if either state was true.  The selected tab reports the Hovered state when closing it.  The non-selected tabs report Pressed.

Might be a good candidate subject for a future tutorial given the complexity.





Similar Topics


Reading This Topic