Newbie: how to create an object "on" another object

S

Steve Thackery

Sorry if this is a silly question, but I'm struggling with what is probably
really simple, if I could but see it.

As a learning exercise I'm writing a simple text editor, which has a tab
control to allow editing of multiple text files. Each TabPage should have a
RichTextBox on it. When I create a new TabPage, I want to place a
RichTextBox on it.

I can create a new TabPage easily enough using:

{
TabPage myTabPage = new TabPage("");
tabControl1.TabPages.Add(myTabPage);
}

I can also create a new RichTextBox in code, but for the life of my I can't
see how to create (or place) the new RichTextBox onto the newly created Tab
Page.

In other words, how do I create one object "on" or "in" another?

I'm sorry if this is really simple, but I have puzzled over this for ages,
and would really appreciate some guidance from someone more experienced!

Thanks in advance,

Thack
 
S

Steve Thackery

In other words, how do I create one object "on" or "in" another?

Ah, wait a minute! It looks like I simply set the Parent Property of the
newly created RichTextBox to the new TabPage.

If I've got that wrong, do let me know. Otherwise, sorry to have troubled
you!

Thack
 
C

Cor Ligthert[MVP]

tp.Controls.Clear();
tp.Controls.Add(new TabPage());
tp.Controls[0].Controls.Add(new RichTextBox());

etc.
 
S

Steve Thackery

tp.Controls.Clear();
tp.Controls.Add(new TabPage());
tp.Controls[0].Controls.Add(new RichTextBox());

Great, thank you Cor Ligthert - that's very helpful. I'll be reading up
this whole area in the documentation.

Regards,

Thack
 

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