apmcph
asked on
Add Forms to TabPages dynamically
HI,
Can I Add Windows Forms to TabPages Dynamically? I want my application to show all window forms to TabPages.
My logic is create a Main TabControl and everytime my program open a new form, TabPages will dynamically created in my TabControl and in that i want to place the new form. Is it possible?
Links to tutorials/articles are accepted if it answer my question.
Thanks.
Can I Add Windows Forms to TabPages Dynamically? I want my application to show all window forms to TabPages.
My logic is create a Main TabControl and everytime my program open a new form, TabPages will dynamically created in my TabControl and in that i want to place the new form. Is it possible?
Links to tutorials/articles are accepted if it answer my question.
Thanks.
It won't work unless you set the TopLevel() property of the Form to False:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim frm As New Form1
frm.TopLevel = False
frm.Dock = DockStyle.Fill
frm.FormBorderStyle = Windows.Forms.FormBorderSt yle.None
Dim tp As New TabPage
tp.Controls.Add(frm)
frm.Show()
TabControl1.TabPages.Add(t p)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim frm As New Form1
frm.TopLevel = False
frm.Dock = DockStyle.Fill
frm.FormBorderStyle = Windows.Forms.FormBorderSt
Dim tp As New TabPage
tp.Controls.Add(frm)
frm.Show()
TabControl1.TabPages.Add(t
End Sub
ASKER
Idle,
How about if i want to remove tab when i close the form?
How about if i want to remove tab when i close the form?
ASKER
I want to have a close button on the top-right side of the Tab.
thanks
thanks
Something like...
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim frm As New Form1
frm.TopLevel = False
frm.FormBorderStyle = Windows.Forms.FormBorderSt yle.FixedT oolWindow
frm.Dock = DockStyle.Fill
AddHandler frm.FormClosed, AddressOf frm_FormClosed
Dim tp As New TabPage
frm.Tag = tp
tp.Controls.Add(frm)
frm.Show()
TabControl1.TabPages.Add(t p)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim frm As New Form1
frm.TopLevel = False
frm.FormBorderStyle = Windows.Forms.FormBorderSt
frm.Dock = DockStyle.Fill
AddHandler frm.FormClosed, AddressOf frm_FormClosed
Dim tp As New TabPage
frm.Tag = tp
tp.Controls.Add(frm)
frm.Show()
TabControl1.TabPages.Add(t
End Sub
ASKER
Idle,
Yes it has close button but only the form were closed, and not remove the TabPage where the form contained.
thanks
Yes it has close button but only the form were closed, and not remove the TabPage where the form contained.
thanks
That's because I forgot to include some code for ya... sorry!
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim frm As New Form1
frm.TopLevel = False
frm.FormBorderStyle = Windows.Forms.FormBorderSt yle.FixedT oolWindow
frm.Dock = DockStyle.Fill
AddHandler frm.FormClosed, AddressOf frm_FormClosed
Dim tp As New TabPage
frm.Tag = tp
tp.Controls.Add(frm)
frm.Show()
TabControl1.TabPages.Add(t p)
End Sub
Private Sub frm_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormC losedEvent Args)
TabControl1.TabPages.Remov e(sender.t ag)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim frm As New Form1
frm.TopLevel = False
frm.FormBorderStyle = Windows.Forms.FormBorderSt
frm.Dock = DockStyle.Fill
AddHandler frm.FormClosed, AddressOf frm_FormClosed
Dim tp As New TabPage
frm.Tag = tp
tp.Controls.Add(frm)
frm.Show()
TabControl1.TabPages.Add(t
End Sub
Private Sub frm_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormC
TabControl1.TabPages.Remov
End Sub
ASKER
Idle,
How do i do that in c#? I think i need to implement delegate and event for this.
Sorry im new to windows application using .net/c#.
thanks.
How do i do that in c#? I think i need to implement delegate and event for this.
Sorry im new to windows application using .net/c#.
thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
yourTabPage.Controls.Add(y
yourForm.Dock = DockStyle.Fill;