protected override void OnDragDrop(DragEventArgs drgevent)
{
base.OnDragDrop(drgevent);
if (drgevent.Data.GetDataPresent(typeof(TabPage)))
{
drgevent.Effect = DragDropEffects.Move;
TabPage dragTab = (TabPage)drgevent.Data.GetData(typeof(TabPage));
if (this.ActiveTab == dragTab){
return;
}
// Capture insert point and adjust for removal of tab
// We cannot assess this after removal as differeing tab sizes will cause
// inaccuracies in the activeTab at insert point.
int insertPoint = this.ActiveIndex;
if (dragTab.Parent.Equals(this) && this.TabPages.IndexOf(dragTab) < insertPoint){
insertPoint --;
}
if (insertPoint < 0){
insertPoint = 0;
}
// Remove from current position (could be another tabcontrol)
((TabControl)dragTab.Parent).TabPages.Remove(dragTab);
// Add to current position
this.TabPages.Insert(insertPoint, dragTab);
this.SelectedTab = dragTab;
// deal with hidden tab handling?
}
}