Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

If someone can help me with this it will be much appreciated, all I want is code that will allow me to change tab pages while dragging a treenode from a treeview that is OUTSIDE the tabcontrol AND hovering over a tabpage that is NOT already open(selected).

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
270 views
Welcome To Ask or Share your Answers For Others

1 Answer

The DragOver event will be fired when the mouse moves over the tabcontrol while the drag action is still in effect. You can use similar logic to the mousemove logic in Change SelectedTab of TabControl on MouseOver in your DragOver handler to make the tabs switch.

Edit:

I did a little MSDN research and found a likely issue. DragOver coordinates are ScreenCoordinates while the tab rectangle in the sample code is in client coordinates. You will need to convert the drag coordinates before the hit check.

            Point clientPoint = tabControl1.PointToClient(new Point(e.X, e.Y));

Edit2:

Put together a trivial app with a TreeView and a TabControl and the following DragOver handler switched tabs correctly as I dragged over the tabs:

    private void tabControl1_DragOver(object sender, DragEventArgs e)
    {
        e.Effect = DragDropEffects.All;

        Point clientPoint = tabControl1.PointToClient(new Point(e.X, e.Y));

        for (int i = 0; i < tabControl1.TabCount; i++)
        {
            if (tabControl1.GetTabRect(i).Contains(clientPoint) && tabControl1.SelectedIndex != i)
            {
                tabControl1.SelectedIndex = i;
            }
        }

    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...