Badro Niaimi Badro Niaimi - 13 days ago 6
C# Question

How to add a context menu to a supertabControl

I'm using

DotNetBar
component
SuperTabControl
, and I want to display the context menu if the user right click a tab, I found the following code but the problem is my
SuperTabControl
doesn't have the GetTabRect function.

if (e.Button == MouseButtons.Right)
{
for (int i = 0; i < this.superTabControl1.Tabs.Count; ++i)
{
Rectangle r = this.superTabControl1.GetTabRect(i);
if (r.Contains(e.Location))
{
//display menu
}
}
}

Answer

As long as there is no answer for my question, I used this code in order to manage closing tabs basing on selected option on my context menu. To close all the tabs except the seelcted one I used this code.

for (int i = this.superTabControl1.Tabs.Count - 1; i >= 0; i--)
            {
                BaseItem item = this.superTabControl1.Tabs[i];
                if (!item.Equals(this.superTabControl1.SelectedTab))
                {
                    (item as SuperTabItem).Close();
                }
            }

To close all the tabs.

 for (int i = this.superTabControl1.Tabs.Count - 1; i > 0; i--)
            {
                BaseItem item = this.superTabControl1.Tabs[i];
                (item as SuperTabItem).Close();
            }

To close the selected Tab I used this code:

this.superTabControl1.SelectedTab.Close();