tabcontrol - VB.Net 拖动和分离 tabpages

  显示原文与译文双语对照的内容
100 0

在一个选项卡控件中有几个 tabpages,我想有人知道如何将tabpages从选项卡控制and到他们自己的"窗体"中,然后将它们放到自己的中?

我正在使用 VB.Net,并且找到了多种方法,可以以在rtc上移动 tabpages,但是如何实际地分离ipqos和 on 。

时间:原作者:0个回答

99 3

假设,本质上你必须创建一个新的表单,并且一个新的rtc来保存你计划移动的rtc 。

以最简单的形式:

Private Sub TabControl1_MouseMove(sender As Object, e As MouseEventArgs) Handles TabControl1.MouseMove
 If (e.Button = MouseButtons.Left) Then
 TabControl1.DoDragDrop(TabControl1.SelectedTab, DragDropEffects.Move)
 End If
End Sub
Private Sub TabControl1_GiveFeedback(sender As Object, e As GiveFeedbackEventArgs) Handles TabControl1.GiveFeedback
 e.UseDefaultCursors = False
End Sub
Private Sub TabControl1_QueryContinueDrag(sender As Object, e As QueryContinueDragEventArgs) Handles TabControl1.QueryContinueDrag
 If Control.MouseButtons <> MouseButtons.Left Then
 e.Action = DragAction.Cancel
 Dim f As New Form
 f.Size = New Size(400, 300)
 f.StartPosition = FormStartPosition.Manual
 f.Location = MousePosition
 Dim tc As New TabControl
 tc.Dock = DockStyle.Fill
 tc.TabPages.Add(TabControl1.SelectedTab)
 f.Controls.Add(tc)
 f.Show()
 Me.Cursor = Cursors.Default
 Else
 e.Action = DragAction.Continue
 Me.Cursor = Cursors.Help
 End If
End Sub
原作者:
129 3

这里我想根据LarsTech的代码来提交我个人的改进。这里版本允许选项卡在窗体关闭时返回原始父级,并要求用户在拖动事件之前将选项卡拖离。

Dim pTabControlClickStartPosition As Point
Dim iTabControlFlyOffPixelOffset As Integer = 20
Private Sub TabControlMain_MouseDown(sender As Object, e As MouseEventArgs) Handles TabControlMain.MouseDown
 If (e.Button = MouseButtons.Left) Then
 pTabControlClickStartPosition = e.Location
 End If
End Sub
Private Sub TabControlMain_MouseMove(sender As Object, e As MouseEventArgs) Handles TabControlMain.MouseMove
 If (e.Button = MouseButtons.Left) Then
 Dim iMouseOffset_X = pTabControlClickStartPosition.X - e.X
 Dim iMouseOffset_Y = pTabControlClickStartPosition.Y - e.Y
 If iMouseOffset_X> iTabControlFlyOffPixelOffset Or iMouseOffset_Y> iTabControlFlyOffPixelOffset Then
 TabControlMain.DoDragDrop(TabControlMain.SelectedTab, DragDropEffects.Move)
 pTabControlClickStartPosition = New Point
 End If
 Else
 pTabControlClickStartPosition = New Point
 End If
End Sub
Private Sub TabControlMain_GiveFeedback(sender As Object, e As GiveFeedbackEventArgs) Handles TabControlMain.GiveFeedback
 e.UseDefaultCursors = False
End Sub
Private Sub TabControlMain_QueryContinueDrag(sender As Object, e As QueryContinueDragEventArgs) Handles TabControlMain.QueryContinueDrag
 If Control.MouseButtons <> MouseButtons.Left Then
 e.Action = DragAction.Cancel
 Dim f As New Form
 f.Size = New Size(800, 400)
 f.StartPosition = FormStartPosition.Manual
 f.Location = MousePosition
 Dim tc As New TabControl
 tc.Dock = DockStyle.Fill
 tc.TabPages.Add(TabControlMain.SelectedTab)
 f.Controls.Add(tc)
 AddHandler f.FormClosing, Sub(sender1 As Object, e1 As EventArgs)
 TabControlMain.TabPages.Add(tc.SelectedTab)
 End Sub
 f.Show()
 Me.Cursor = Cursors.Default
 Else
 e.Action = DragAction.Continue
 Me.Cursor = Cursors.SizeAll
 End If
End Sub
原作者:
...