XtraTabHitInfo hinfo = default(XtraTabHitInfo);

XtraTabPage hoverTab = default(XtraTabPage);

XtraTabPage dragTab = default(XtraTabPage);

XtraTabPage selTab = default(XtraTabPage);

XtraTabPage repTab = default(XtraTabPage);

//

int itemDragIndex = 0;

int dropLocationIndex = 0;

//

// get the tab we are hovering over.

hinfo = xtcMain.CalcHitInfo(xtcMain.PointToClient(new Point(e.X, e.Y)));

//

if ((hinfo.Page != null))

{

hoverTab = hinfo.Page;

//Make sure there is a TabPage being dragged.

if (e.Data.GetDataPresent(typeof(XtraTabPage)))

{

e.Effect = DragDropEffects.Move;

dragTab = (XtraTabPage)e.Data.GetData(typeof(XtraTabPage));

// can't use the TabIndex on the control because it changes

// when we move the tab page.

itemDragIndex = FindIndex(dragTab);

dropLocationIndex = FindIndex(hoverTab);

//Don't do anything if we are hovering over ourself.

if (itemDragIndex != dropLocationIndex)

{

selTab = xtcMain.TabPages[itemDragIndex];

repTab = xtcMain.TabPages[dropLocationIndex];

//

xtcMain.TabPages.Move(dropLocationIndex, selTab);

xtcMain.TabPages.Move(itemDragIndex, repTab);

xtcMain.SelectedTabPage = selTab;

}

}

}

else

{

e.Effect = DragDropEffects.None;

}

在 MouseDown 事件中的code:

CalcRectDragBox(e.X, e.Y);

// Handle Mouse move only if left button is pressed.

if (e.Button == MouseButtons.Left)

{

// If the mouse moves outside the rectangle, start the drag.

if (!rectDragBoxFromMouseDown.Equals(Rectangle.Empty) & !rectDragBoxFromMouseDown.Contains(e.X, e.Y))

{

isDragging = true;

dragOffset = new Point(e.X, e.Y);

Invalidate();

// Proceed with the drag and drop.

DragDropEffects dropEffect = DoDragDrop(xtcMain.SelectedTabPage, DragDropEffects.Move);

// Reset the drag box to avoid reentry of drag.

CalcRectDragBox(e.X, e.Y);

isDragging = false;

dragOffset = Point.Empty;

Invalidate();

}

} 如果你有不同大小的标签,张贴的代码将导致快如闪电的标签之间切换,如果您对重叠的区域的大小不同悬停。 为了防止这种情况,我只是说在dragOver处理一个简单的标志,忽略未来DragOver事件。 在上面的DragOver里面相应的 位置加入这个标志ignoreNextDrag,具体代码如下:

if (itemDragIndex != dropLocationIndex && !ignoreNextDrag)

{

ignoreNextDrag = true;

selTab = tabControlClientModules.TabPages[itemDragIndex];

repTab = tabControlClientModules.TabPages[dropLocationIndex];

//

tabControlClientModules.TabPages.Move(dropLocationIndex, selTab);

tabControlClientModules.TabPages.Move(itemDragIndex, repTab);

tabControlClientModules.SelectedTabPage = selTab;

}

else

{

ignoreNextDrag = false;

}

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐