)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to tear the TabPageAdv as a separate window by dragging it from the WinForms TabControlAdv?

Platform: WinForms |
Control: TabControlAdv |
Published Date: August 18, 2015 |
Last Revised Date: January 30, 2020

Display the tab page as a separate window

TabControlAdv doesn’t have support to tear the TabPageAdv from the TabControlAdv and display it as a separate window. But this requirement can be achieved by handling the following TabControlAdv events.

1. MouseDown

2. MouseMove

3. MouseUp

C#

//Initializes the TabPageAdv
TabPageAdv SelectedPage = null;
bool isMouseDown = false;
bool isDragging = false;
Point mouseDownLocation = Point.Empty;
//The event raises when Mouse button is pressed.
private void tabControlAdv1_MouseDown(object sender, MouseEventArgs e)
{
    if (e.Button == System.Windows.Forms.MouseButtons.Left)
        isMouseDown = true;
    else
    {
        isMouseDown = false;
        isDragging = false;
    }
    mouseDownLocation = e.Location;
}
//The event raises when Mouse is moved from the TabControlAdv
private void tabControlAdv1_MouseMove(object sender, MouseEventArgs e)
{
    if (isMouseDown && e.Button == System.Windows.Forms.MouseButtons.Left && mouseDownLocation.Y != e.Location.Y)
        isDragging = true;
    else
        isDragging = false;
}
//The event is raised when mouse pointer releases the TabControlAdv.
private void tabControlAdv1_MouseUp(object sender, MouseEventArgs e)
{
    //Initializes the newly created form
    Form2 form2 = new Form2();
    if (isDragging)
    {
        form2.Size = this.Size;
        if (this.tabControlAdv1.SelectedTab != null)
        {
            SelectedPage = this.tabControlAdv1.SelectedTab;
            form2.Text = SelectedPage.Text;
            form2.Show();
            //Adds the selected TabPage in Form2
            if (this.tabControlAdv1.TabPages.Count > 0)
                form2.tabControlAdv1.Controls.Add(SelectedPage);
        }
    }
    isMouseDown = false;
    isDragging = false;
}

VB

'Initializes the TabPageAdv
Private SelectedPage As TabPageAdv = Nothing
Private isMouseDown As Boolean = False
Private isDragging As Boolean = False
Private mouseDownLocation As Point = Point.Empty
'The event raises when the Mouse button is pressed.
Private Sub tabControlAdv1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles tabControlAdv1.MouseDown
    If e.Button = System.Windows.Forms.MouseButtons.Left Then
       isMouseDown = True
    Else
       isMouseDown = False
       isDragging = False
    End If
    mouseDownLocation = e.Location
End Sub
'The event is raised when Mouse moves from the TabControlAdv
Private Sub tabControlAdv1_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) Handles tabControlAdv1.MouseMove
    If isMouseDown AndAlso e.Button = System.Windows.Forms.MouseButtons.Left AndAlso mouseDownLocation.Y <> e.Location.Y Then
       isDragging = True
    Else
       isDragging = False
    End If
End Sub
'The event is raised when mouse pointer releases the TabControlAdv.
Private Sub tabControlAdv1_MouseUp(ByVal sender As Object, ByVal e As MouseEventArgs) Handles tabControlAdv1.MouseUp
    'Initializes the newly created form
    Dim form2 As New Form2()
    If isDragging Then
       form2.Size = Me.Size
       If Me.tabControlAdv1.SelectedTab IsNot Nothing Then
          SelectedPage = Me.tabControlAdv1.SelectedTab
          form2.Text = SelectedPage.Text
          form2.Show()
          'Adds the selected TabPage in Form2
          If Me.tabControlAdv1.TabPages.Count > 0 Then
   form2.tabControlAdv1.Controls.Add(SelectedPage)
          End If
       End If
    End If
    isMouseDown = False
    isDragging = False
End Sub

Before separating the tab page from the TabControlAdv

Figure 1: Before separating the TabPageAdv from the TabControlAdv

After separating the tab page from the TabControlAdv

Figure 2: After separating the TabPageAdv from the TabControlAdv

Samples:

C#: Separate_TabControl_C#

VB: Separate_TabControl_VB

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon