Hmm dynamic form problem *RESOLVED*
ok. I have a tabcontrol with a couple dynamiclly created tabs with dynamiclly added controls on them. I am writing a Tear function the when you write click a tab header, you get a popup menu with the oiption to Tear. When selected a new form appears that becomes a torn out version of the ontrol that were on the tab( Get what I mean?). First time its fine on a control with 1 control. But do it again and 2 windows appear. again and 3 windows appear.
But that is not all. With more than 1 control, it ceates a new form for each one.
Oh and when I place the ocntrol form the tab onto the new form, they disappear from the tab. Ok, so I will make the tab invisible until layet. But no, you cant change the visiblity ot tabs either!
Argh.
Anyone got a clue. Here is the relevant Tear code
VB Code:
Private Sub tabClient_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles tabClient.MouseDown
Dim tab As New TabPage()
Dim x As Integer
Dim rect As Rectangle
Dim ctl As Control
Dim holdctl As Control
pos.X = e.X
pos.Y = e.Y
If e.Button = MouseButtons.Right Then ContextMenu1.Show(tabClient, pos)
AddHandler MenuItem1.Click, AddressOf Tear
End Sub
Private Sub Tear(ByVal sender As Object, ByVal e As EventArgs)
Dim tab As New TabPage()
Dim x As Integer
Dim rect As Rectangle
Dim ctl As Control
For x = 0 To tabClient.TabCount - 1
rect = tabClient.GetTabRect(x)
If rect.Contains(pos) Then
Dim test As New Form()
AddHandler test.Closing, AddressOf FormClose
For Each ctl In tabClient.TabPages(x).Controls
test.Controls.Add(ctl)
Next
test.Show()
Exit For
End If
Next
End Sub