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)
Cander asking questions instead of giving answers.... what universe did I wake up in this morning?
I think I understand what you're saying....
Basically you're problem is you have to keep a check to see if an existing child form is present, because if you don't, you have a new TearPage appear on each click.... so everytime the user clicks this certain context Tear option... he/she will keep making more new TearPages?? (bet you're thinking it would be great if you could supressed that handler in the meantime.. ie.. RemoveHandler)
Its not a problem of stopping people from 'tearing' again. The problem is. Tear the first time and close the new torn window. Tear again, and 2 windows appear. Close both of those. Tear again and 3 windows appear! See what I mean?
Plus, tabs with more than 1 control makes a new form for each control isntead of putting them all on 1 like I thought it should.
I can only guess that somehow when the user closes the form, it does not dispose, and that handler remains. So when they click on a menuItem again, it now fires off two events, running your sub twice. And the more they click and close, the more event handlers are getting assigned.
I always used MyDynamicForm.Dispose .... and haven't had a problem... but maybe you should explicitly using RemoveHandler...
Last edited by nemaroller; Jun 3rd, 2003 at 12:24 PM.
I can't quite figure out why its not working, although I am new to .NET.
The following is some code I wrote to create a tabpage on the fly, prompt for the Text field and put a textbox on it. It works fine. Maybe you will see something I don't.
Private Sub TopicAddMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TopicAddMenuItem.Click
' Create a new tab and add a rich text box to it
' Set up variables to prompt for Tab name
Dim message, title As String
Dim myValue As Object
message = "Enter Tab Name" ' Set prompt.
title = "SmartPad" ' Set title.
' Set up variables for new Tab page and Rich Text Box
Dim TabPageNew As System.Windows.Forms.TabPage
Dim TextBoxNew As System.Windows.Forms.TextBox
TextBoxNew = New System.Windows.Forms.TextBox()
TextBoxNew.Location = New System.Drawing.Point(8, 8)
TextBoxNew.Name = "TextBoxNew"
TextBoxNew.Size = New System.Drawing.Size(520, 288)
TextBoxNew.Multiline = True
TextBoxNew.TabIndex = 0
TextBoxNew.Text = ""
'TabPageNew
'
TabPageNew = New System.Windows.Forms.TabPage()
TabPageNew.Controls.AddRange(New System.Windows.Forms.Control() {TextBoxNew})
TabPageNew.Location = New System.Drawing.Point(4, 22)
TabPageNew.Name = "TabPageNew"
TabPageNew.Size = New System.Drawing.Size(528, 302)
TabPageNew.TabIndex = 0
' Display message, title and get the Tab Name
Do
myValue = InputBox(message, title)
Loop Until myValue <> ""
TabPageNew.Text = myValue
' add the control, make the new tab active and bring focus to the rich text box
Me.SmartPadTabControl.Controls.AddRange(New System.Windows.Forms.Control() {TabPageNew})
Me.SmartPadTabControl.SelectedIndex = Me.SmartPadTabControl.TabCount - 1
TextBoxNew.Focus()
End Sub
Creating the tab page isnt the problem. I have an option where a user can create a popup form which becomes a copy of the selected Tab(ie all the controls on it).
So i do a for loop that adds each control on the tab page, tothe new form. Prblem is, when you add a control from the tab page to th form, it is removed from the Tabpage, and after that the for loop bugs out. I dont get it.
for anyone that can help with second issue. Here is the code where I build a tab with 2 textboxes.
It would be nice if you tell me where is the problem with that piece of code?! Maybe I am dumb, cause i see no problem in the code and cant figure out what you are talking about.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
and tried to run it in an application. I put a tab control on a blank form, passed it to Panel_init and displayed the form. The text boxes do not appear on the new tab page. Yet, I do the same thing in my code, which I posted, and the textbox works fine.
IAC, if I can come up with anything I will let you know.
Originally posted by ggprogram I guess I am confused. I took your
Public Sub Panel_Init(ByRef tab As TabControl)
and tried to run it in an application. I put a tab control on a blank form, passed it to Panel_init and displayed the form. The text boxes do not appear on the new tab page. Yet, I do the same thing in my code, which I posted, and the textbox works fine.
IAC, if I can come up with anything I will let you know.
Thanks. I have never been in a situation like this years where I am completly boggled as to why it wont work.
It may very well just be a bug with the TabControl because this SHOULD be straightforward. Take controls from one container and stick it on another is elementary code.
Well, both textboxes are being added.... only one shows though... and I noticed when I resize your form, the first textbox seems ANCHORED to all sides.... so i removed the anchor, didn't change anything...
My guess: Your first textbox is sitting atop (or behind) the second textbox... and since you aren't defining a position, they are effectively covering up the other one...
Somehow Controls.Add is Moving the textbox,not copying the textbox. So I am going to guess that somewhere a shallow copy of a pointer is being made. IOW, when you add the control to the form, a pointer is being changed rather than a new textbox being created. BAsically you want to clone the original textbox and assign it to the new form.
If you set a Watch on ctl and step through with the degugger, on the first pass, ctl is the first textbox. On the second, its Nothing. Thats becasue there is now one less control in the collection.
You can prove this to yourself by running the loop twice:
For Each ctl In tabClient.TabPages(x).Controls
test.Controls.Add(ctl)
Next
For Each ctl In tabClient.TabPages(x).Controls
test.Controls.Add(ctl)
Next
In thinking about it more, the workaround should be easy. In the loop create a new textbox, copy the attributes from the original, and then Add the new one to the new form.
Originally posted by nemaroller Well, both textboxes are being added.... only one shows though... and I noticed when I resize your form, the first textbox seems ANCHORED to all sides.... so i removed the anchor, didn't change anything...
My guess: Your first textbox is sitting atop (or behind) the second textbox... and since you aren't defining a position, they are effectively covering up the other one...
No. The tetbox is not being added. Already checked for that.
Originally posted by ggprogram In thinking about it more, the workaround should be easy. In the loop create a new textbox, copy the attributes from the original, and then Add the new one to the new form.
Not so easy. The whole system needs to be dynamic as these tabs can be added via 3rd party plugins. So i cant expect only certain controls.