Beispiel #1
0
        public void ux_tabcontrolDragDropEvent(TabControl ux_tabcontrolDataview, DragEventArgs e)
        {
            if (e.AllowedEffect == e.Effect)
            {
                // Convert the mouse coordinates from screen to client...
                System.Drawing.Point ptClientCoord = ux_tabcontrolDataview.PointToClient(new System.Drawing.Point(e.X, e.Y));

                int destinationTabPageIndex = -1;
                int originalTabPageIndex = -1;

                // Attempt to find where the tabpage should be dropped...
                for (int i = 0; i < ux_tabcontrolDataview.TabPages.Count; i++)
                {
            //if (ux_tabcontrolDataview.TabPages[i] == e.Data.GetData(typeof(TabPage))) originalTabPageIndex = i;
            if (ux_tabcontrolDataview.TabPages[i] == e.Data.GetData("System.Windows.Forms.TabPage")) originalTabPageIndex = i;
                    if (ux_tabcontrolDataview.GetTabRect(i).Contains(ptClientCoord)) destinationTabPageIndex = i;
                }

                // Now create a copy of the tabpage that is being moved so that
                // you can remove the orginal and insert the copy at the right spot...
                TabPage newTabPage = new TabPage();
            //newTabPage.Text = ((TabPage)e.Data.GetData(typeof(TabPage))).Text;
            newTabPage.Text = ((TabPage)e.Data.GetData("System.Windows.Forms.TabPage")).Text;
            //newTabPage.Tag = ((TabPage)e.Data.GetData(typeof(TabPage))).Tag;
            newTabPage.Tag = ((TabPage)e.Data.GetData("System.Windows.Forms.TabPage")).Tag;
                ux_tabcontrolDataview.TabPages.Insert(destinationTabPageIndex, newTabPage);
                ux_tabcontrolDataview.SelectTab(destinationTabPageIndex);
                if (originalTabPageIndex < destinationTabPageIndex)
                {
                    ux_tabcontrolDataview.TabPages.RemoveAt(originalTabPageIndex);
                }
                else
                {
                    ux_tabcontrolDataview.TabPages.RemoveAt(originalTabPageIndex + 1);
                }
            }
        }
Beispiel #2
0
        public void ux_tabcontrolDragOverEvent(TabControl ux_tabcontrolDataview, DragEventArgs e)
        {
            // Convert the mouse coordinates from screen to client...
            System.Drawing.Point ptClientCoord = ux_tabcontrolDataview.PointToClient(new System.Drawing.Point(e.X, e.Y));
            //int destinationTabPage = ux_tabcontrolDataview.TabPages.IndexOf((TabPage)e.Data.GetData(typeof(TabPage)));
            if (e.Data.GetDataPresent("System.Windows.Forms.TabPage"))
            {
            int destinationTabPage = ux_tabcontrolDataview.TabPages.IndexOf((TabPage)e.Data.GetData("System.Windows.Forms.TabPage"));

            // Attempt to find the tabpage that is being dragged over...
            for (int i = 0; i < ux_tabcontrolDataview.TabPages.Count; i++)
            {
            if (ux_tabcontrolDataview.GetTabRect(i).Contains(ptClientCoord)) destinationTabPage = i;
            }

            ////if (e.Data.GetDataPresent(typeof(TabPage)) &&
            //if (e.Data.GetDataPresent("System.Windows.Forms.TabPage") &&
            ////ux_tabcontrolDataview.TabPages[destinationTabPage] != (TabPage)e.Data.GetData(typeof(TabPage)) /* &&
            //ux_tabcontrolDataview.TabPages[destinationTabPage] != (TabPage)e.Data.GetData("System.Windows.Forms.TabPage") /* &&
            //                destinationTabPage != ux_tabcontrolDataview.TabPages.IndexOfKey("ux_tabpageDataviewNewTab")*/
            //                                                                                                                      )
            if (ux_tabcontrolDataview.TabPages[destinationTabPage] != (TabPage)e.Data.GetData(typeof(TabPage)))
            {
            e.Effect = DragDropEffects.Move;
            }
            else
            {
            e.Effect = DragDropEffects.None;
            }
            }
        }
        private int getHoverTabIndex(TabControl tc)
        {
            for (int i = 0; i < tc.TabPages.Count; i++)
            {
                if (tc.GetTabRect(i).Contains(tc.PointToClient(Cursor.Position)))
                    return i;
            }

            return -1;
        }