Change position of a tabpage on a tabcontrol???? 
Author Message
 Change position of a tabpage on a tabcontrol????

I was wondering if anyone knew how to change the position of a tabpage on a
tabcontrol.

Say the tabcontrol has 3 tabpages on it.  They are named tabpage1, tabpage2,
tabpage3 and ordered respectfully.  I want the user to be able to press a
button on the page and move say tabpage 2 to the position that tabpage1 is
in.  The new order would be tabpage2, tabpage1, and tabpage3.

I have not found a way to do this as of yet and can not seem to find any
samples that would help me in doing this, so if anyone could point me in the
right direction I would appreciate it.

Thanks,

Todd



Mon, 10 Oct 2005 03:55:33 GMT  
 Change position of a tabpage on a tabcontrol????
Todd,

You are discovering the joys 8-( of using the Microsoft
tab control.  I have had problems with it also.  The big
problem you have is some how swapping all the controls on
a tab page with another.  You can use an array of panel
controls, 1 per tab, additionally you can just swap the
tab label names.  Finally, when the user selects the tab
of interest, vector through a mapping of tab to panel and
paint the panel in all its glory.  Never said it was easy.

Pat

Quote:
>-----Original Message-----

>I was wondering if anyone knew how to change the position
of a tabpage on a
>tabcontrol.

>Say the tabcontrol has 3 tabpages on it.  They are named
tabpage1, tabpage2,
>tabpage3 and ordered respectfully.  I want the user to be
able to press a
>button on the page and move say tabpage 2 to the position
that tabpage1 is
>in.  The new order would be tabpage2, tabpage1, and
tabpage3.

>I have not found a way to do this as of yet and can not
seem to find any
>samples that would help me in doing this, so if anyone

could point me in the

- Show quoted text -

Quote:
>right direction I would appreciate it.

>Thanks,

>Todd

>.



Mon, 10 Oct 2005 04:38:02 GMT  
 Change position of a tabpage on a tabcontrol????
Since the IDE allows you to do this, I figured it was doable.
Unfortunately, I had to brute force it.  Here is some code for the "MoveUp"
issue.  I'll leave it to you to derive the "MoveDown".

    Private Sub MoveTabPageUpOneSlot(ByVal TabControlToChange As TabControl,
ByVal Page As TabPage)
        Dim iPosition As Integer = TabControlToChange.TabPages.IndexOf(Page)
        If (iPosition = 0) Then Return 'Already first
        iPosition -= 1
        If (Not TabControlToChange.TabPages.Contains(Page)) Then Return
'Page not part of the control
        Dim oTabPage As TabPage
        'Copy the pages someplace
        Dim oPages As New ArrayList()
        For Each oTabPage In TabControlToChange.TabPages
            oPages.Add(oTabPage)
        Next
        TabControlToChange.TabPages.Clear()
        Dim j As Integer
        For j = 0 To oPages.Count - 1
            oTabPage = CType(oPages(j), TabPage)
            If (j = iPosition) Then TabControlToChange.TabPages.Add(Page)
            If (Not oTabPage Is Page) Then
TabControlToChange.TabPages.Add(oTabPage)
        Next
        TabControlToChange.Invalidate() 'Forces tab control to be redrawn
    End Sub


Quote:

> I was wondering if anyone knew how to change the position of a tabpage on
a
> tabcontrol.

> Say the tabcontrol has 3 tabpages on it.  They are named tabpage1,
tabpage2,
> tabpage3 and ordered respectfully.  I want the user to be able to press a
> button on the page and move say tabpage 2 to the position that tabpage1 is
> in.  The new order would be tabpage2, tabpage1, and tabpage3.

> I have not found a way to do this as of yet and can not seem to find any
> samples that would help me in doing this, so if anyone could point me in
the
> right direction I would appreciate it.

> Thanks,

> Todd



Mon, 10 Oct 2005 05:05:23 GMT  
 Change position of a tabpage on a tabcontrol????
Thanks for the response.  I have found a way that you might be interested
in.  I first declared a collection.
I use collection to store the tabpages in the order that I wanted them in.
Once I have them in the order I want them to be in,
I clear out the tabpages on the tabcontrol and then loop through the
collection and place them back on the tabcontrol.
I found this while doing some more research on the subject.
Here is the code that I used,  I'm also changing the view in a treeview as
well, so that is why I have the treenode declare.

'Declare a clone of the selected node.
Dim objNode As TreeNode = Me.tvwProduct.SelectedNode.Clone
Dim colTabpages As New Collection()
Dim tpPage As TabPage
Dim i As Integer

'Declare a variable for the new and old indexes.
Dim intNewIndex As Integer
Dim intOldIndex As Integer = Me.tvwProduct.SelectedNode.Index

'Check if the old index is greater than one, if not then it is at the top of
the tree.
If intOldIndex > 0 Then

    'Get the new index.
    intNewIndex = intOldIndex - 1

    'Remove the old node.
    Me.tvwProduct.Nodes(0).Nodes(0).Nodes.RemoveAt(intOldIndex)

    'Insert the cloned node into the position it is supposed to be.
    Me.tvwProduct.Nodes(0).Nodes(0).Nodes.Insert(intNewIndex, objNode)
    Me.tvwProduct.SelectedNode =
Me.tvwProduct.Nodes(0).Nodes(0).Nodes(intNewIndex)
    Me.tvwProduct.SelectedNode.ExpandAll()

    'Change the order of the tabpages (forms).
    For i = 0 To Me.tabForms.TabPages.Count - 1
    'Check if the form is at the new index.
        If i = intNewIndex Then
        'Swap the tabpages that is changing with the tabpage that it is
going to.
            colTabpages.Add(Me.tabForms.TabPages(intOldIndex))
            colTabpages.Add(Me.tabForms.TabPages(i))
            i = intOldIndex
        Else
            colTabpages.Add(Me.tabForms.TabPages(i))
        End If
    Next

   'Clear the tabcontrol of all tabpages.
    Me.tabForms.TabPages.Clear()

    'Add the tabpages back in the order that the user changed.
    For i = 1 To colTabpages.Count
        Me.tabForms.TabPages.Add(colTabpages.Item(i))
    Next

    Me.tabForms.SelectedTab = Me.tabForms.TabPages(intNewIndex)
End If


Quote:
> Todd,

> You are discovering the joys 8-( of using the Microsoft
> tab control.  I have had problems with it also.  The big
> problem you have is some how swapping all the controls on
> a tab page with another.  You can use an array of panel
> controls, 1 per tab, additionally you can just swap the
> tab label names.  Finally, when the user selects the tab
> of interest, vector through a mapping of tab to panel and
> paint the panel in all its glory.  Never said it was easy.

> Pat
> >-----Original Message-----

> >I was wondering if anyone knew how to change the position
> of a tabpage on a
> >tabcontrol.

> >Say the tabcontrol has 3 tabpages on it.  They are named
> tabpage1, tabpage2,
> >tabpage3 and ordered respectfully.  I want the user to be
> able to press a
> >button on the page and move say tabpage 2 to the position
> that tabpage1 is
> >in.  The new order would be tabpage2, tabpage1, and
> tabpage3.

> >I have not found a way to do this as of yet and can not
> seem to find any
> >samples that would help me in doing this, so if anyone
> could point me in the
> >right direction I would appreciate it.

> >Thanks,

> >Todd

> >.



Mon, 10 Oct 2005 05:06:29 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. TabControl and TabPage

2. GETTING FOCUS TO TabControl.Tabpage?

3. scroll for tabpage on tabcontrol

4. Hiding tabPage in TabControl

5. Tabcontrol (on user defined control) loses tabpage collection

6. selected tabpage one tabcontrol

7. Trick: How to hide TabControl's tabs (not tabpages)

8. tabControl and tabPages problem

9. Inheriting TabControl with TabPage

10. I can't find TabPages to place on my TabControl

11. HowTO hide TabPage in TabControl

12. Change the color of a TabControl

 

 
Powered by phpBB® Forum Software