private void MainTabControl_DragDrop(object sender, DragEventArgs e) { TabPage source = (TabPage)e.Data.GetData(typeof(TabPage)); SetCurrStatus($"MainTabControl_DragDrop:{source}"); if (source != null) { for (int i = 0; i < MainTabControl.TabPages.Count; i++) { if (MainTabControl.GetTabRect(i).Contains(e.X, e.Y)) { //var tab = MainTabControl.TabPages[i]; //SetCurrStatus($"拖动开始:{MainTabControl.TabPages[i].Text},AlowDrop:{tab.AllowDrop}"); //tab.DoDragDrop(e, DragDropEffects.Move); if (MainTabControl.TabPages.IndexOf(source) != i) { e.Effect = DragDropEffects.Move; TabAdapter.Swap(MainTabControl.TabPages.IndexOf(source), i); SetCurrStatus($"拖动结束:{e.Data}"); return; } } } } e.Effect = DragDropEffects.None; }
private void MainTabControl_DragOver(object sender, DragEventArgs e) { TabPage source = (TabPage)e.Data.GetData(typeof(TabPage)); //SetCurrStatus($"MainTabControl_DragOver:{source}"); if (source != null) { for (int i = 0; i < MainTabControl.TabPages.Count; i++) { if (MainTabControl.GetTabRect(i).Contains(MainTabControl.PointToClient(new Point(e.X, e.Y)))) { if (MainTabControl.TabPages.IndexOf(source) != i) { e.Effect = DragDropEffects.Move; TabAdapter.Swap(MainTabControl.TabPages.IndexOf(source), i); MainTabControl.SelectedTab = source; SetCurrStatus($"拖动结束:{source.Text}"); return; } } } } e.Effect = DragDropEffects.None; }