Reputation: 4655
I have panel with few textboxes, datagridview, etc... - Panel1.
Also, I have TabControl with 3 TabPages (may be more) on which I would like to add that Panel1.
I don't know is this good idea because of events which will be happen in tab pages and collecting data from textboxes. Will it be better do build one usercontrol instead of panel?
But, ok...
How to add that panel to tab pages?
I try:
Panel1.Location = New Point(50, 50)
TabControl1.TabPages(0).Controls.Add(Panel1)
Panel1.Location = New Point(60, 50)
TabControl1.TabPages(1).Controls.Add(Panel1)
Panel1.Location = New Point(70, 50)
TabControl1.TabPages(2).Controls.Add(Panel1)
But this, of course don't work.
Upvotes: 0
Views: 1625
Reputation: 71
I am a huge fan of panels! And who doesn't love tabs? I don't believe you should have any issues with events, as long as they are setup correctly at the panel / control level.
A basic way to handle:
'a new panel
Dim pnlToAdd As New Panel
'just to see the panel added - add your panel properties here
pnlToAdd.BackColor = Color.Red
'add something to panel
Dim txtToAdd As New TextBox
'add a control to test panel
pnlToAdd.Controls.Add(txtToAdd)
'create a tabpage
Dim tabPageRef As New TabPage
'set the tabpage to be your desired tab
tabPageRef = TabControl1.TabPages(1)
'add the panel
tabPageRef.Controls.Add(pnlToAdd)
Upvotes: 1