TabControl and Sharing Controls on pages

S

scorpion53061

I am trying to be able to share a groupbox and its related controls
among all of my tab pages.

This does not error but the controls do not appear either.

Thank you for your help!!



Private Sub TabControl1_TabIndexChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles TabControl1.TabIndexChanged
Dim i As New TabControl.TabPageCollection(Me.TabControl1)
Dim COUNT As Integer
Dim J As Integer
J = TabControl1.SelectedIndex
For COUNT = 0 To i.Count - 1
If
TabControl1.TabPages(COUNT).Controls.Contains(Me.GroupBox1) Then
TabControl1.TabPages(COUNT).Controls.Remove(Me.GroupBox1)
End If
Next
TabControl1.TabPages(J).Controls.Add(Me.GroupBox1)

'do I need to add the location and sizes again as well as it member
controls?
End Sub
 
G

Guest

put
Me.GroupBox1.visible = True
after
TabControl1.TabPages(J).Controls.Add(Me.GroupBox1)
 
S

scorpion53061

No that did not work.

I was using the wrong event....

Private Sub TabControl1_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged
Dim i As New TabControl.TabPageCollection(Me.TabControl1)

Dim COUNT As Integer
Dim J As Integer
J = TabControl1.SelectedIndex

For COUNT = 0 To i.Count - 1
If TabControl1.TabPages(COUNT).Controls.Contains(GroupBox1)
Then
TabControl1.TabPages(COUNT).Controls.Remove(GroupBox1)
End If
Next
TabControl1.TabPages(J).Controls.Add(GroupBox1)
End Sub
 
H

Herfried K. Wagner [MVP]

scorpion53061 said:
I am trying to be able to share a groupbox and its related controls among
all of my tab pages.

Place the groupbox outside a tabpage and then move it over the tabcontrol.
Maybe you'll have to choose "Bring to front" to show the groupbox in front
of the tabcontrol.
 
M

Mick Doherty

Thats very complicated. A Control can only be in one place at any one time
so theres no need to remove it from the tabpage its on.
You don't need to search the tabpages to find a control that you know the
name of.

\\\
Sub TabControl1_SelectedIndexChanged(...)...
TabControl1.SelectedTab.Controls.Add(GroupBox1)
End Sub
///
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top