private void xtraTabControl_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
xtraTabControl.ContextMenuStrip = null;
//TreeListHitInfo hInfo = treeList1.CalcHitInfo(new Point(e.X, e.Y));
//TreeListNode node = hInfo.Node;
//treeList1.FocusedNode = node;
xtraTabControl.ContextMenuStrip = contextMenuStrip1;
}
}
private void xtraTabControl_MouseUp(object sender, MouseEventArgs e)
{
//TreeList tree = sender as TreeList;
//if (e.Button == MouseButtons.Right
// && ModifierKeys == Keys.None
// && treeList1.State == TreeListState.Regular)
//{
// Point p = new Point(Cursor.Position.X, Cursor.Position.Y);
// TreeListHitInfo hitInfo = tree.CalcHitInfo(e.Location);
// if (hitInfo.HitInfoType == HitInfoType.Cell)
// {
// tree.SetFocusedNode(hitInfo.Node);
// }
// if (tree.FocusedNode != null)
// {
// popupMenu1.ShowPopup(p);
// }
//}
}
/// <summary>
/// 关闭当前页签
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tsmCloseCurrent_Click(object sender, EventArgs e)
{
string name = xtraTabControl.SelectedTabPage.Text;//得到关闭的选项卡的text
foreach (XtraTabPage page in xtraTabControl.TabPages)//遍历得到和关闭的选项卡一样的Text
{
if (page.Text == name)
{
xtraTabControl.TabPages.Remove(page);
page.Dispose();
return;
}
}
}
/// <summary>
/// 关闭其它页签
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tsmCloseOther_Click(object sender, EventArgs e)
{
int index = xtraTabControl.SelectedTabPageIndex;//得到关闭的选项卡的索引
for (int i = xtraTabControl.TabPages.Count - 1; i > 0; i--)
{
if (i != index)
{
xtraTabControl.TabPages.RemoveAt(i);
}
}
}
/// <summary>
/// 关闭所有页签
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tsmCloseAll_Click(object sender, EventArgs e)
{
for (int i = xtraTabControl.TabPages.Count-1; i >0; i--)
{
xtraTabControl.TabPages.RemoveAt(i);
// xtraTabControl.TabPages[i].Dispose();
}
}
/// <summary>
/// 双击关闭
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void xtraTabControl_DoubleClick(object sender, EventArgs e)
{
XtraTabHitInfo tabHitInfo = ((XtraTabControl)sender).CalcHitInfo(((XtraTabControl)sender).PointToClient(Control.MousePosition));
((XtraTabControl)sender).TabPages.Remove(tabHitInfo.Page);
}
![](//img-blog.csdn.net/20160222164919640?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)