Adding a Form to a TabPage

T

TN

I can add a button to a TabPage, how come I can't add a Form? The Form
never gets realized on the page, but a button can :-(

f = new System.Windows.Forms.Form();
b = new Button();
b.Text = "Hello";
f.Text = "NEW";
f.Size = new Size(100, 100);
f.Controls.Add(b);
f.TopLevel = false;
f.Dock = DockStyle.Fill;

t = new TabPage("Cash Receipts");
f.Parent = t;
t.Controls.Add(f);
tabControl1.TabPages.Add(t);
 
T

TN

TN said:
I can add a button to a TabPage, how come I can't add a Form? The Form
never gets realized on the page, but a button can :-(

f = new System.Windows.Forms.Form();
b = new Button();
b.Text = "Hello";
f.Text = "NEW";
f.Size = new Size(100, 100);
f.Controls.Add(b);
f.TopLevel = false;
f.Dock = DockStyle.Fill;

t = new TabPage("Cash Receipts");
f.Parent = t;
t.Controls.Add(f);
tabControl1.TabPages.Add(t);

(sticking tail between legs)

f.Show();
 
R

RHeuvel

Hi,

what about having a TabControl hosting multiple tabpages each hosting its
own form?
The below works fine for 1 hosted form but as soon as you add further forms
to further tabpages the additionial forms will not show (unless you politely
ask them to do so multiple times and are willing to wait a bit...)
 

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