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

  • Thread starter Thread starter Steve Thackery
  • Start date Start date
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
 
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
 
tp.Controls.Clear();
tp.Controls.Add(new TabPage());
tp.Controls[0].Controls.Add(new RichTextBox());

etc.
 
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
 
Back
Top