Problem with tabs

Hi.
My goal is to create a text editor with tabs, so I can open multiple files in tabs. My problem is that i cannot access controls in tab pages. I can only access first page. I designed first page in visual editor. Other pages may be created by clicking specified button.

Code of this button (click event):

[code]
private void tripNewpage_Click(object sender, EventArgs e)
{
TabPage newtab = new TabPage("new");
MyTabs.Controls.Add(newtab);
RichTextBox rchText = new RichTextBox();
rchText.Name = "rchText";
rchText.ContextMenuStrip = contextMenuStrip1;
rchText.Dock = DockStyle.Fill;
MyTabs.SelectedTab = newtab;
newtab.Controls.Add(rchText);
}
[/code]

This creates a new tab with a richtextbox control. I'm able to write inside the control, but i cannot use functions i used in first page.

Code of button that edites rchText control which is automatically created in first tab after running program:

[code]
private void tripBold_Click(object sender, EventArgs e)
{
if (rchText.SelectionFont == null)
{
return;
}

FontStyle style = rchText.SelectionFont.Style;

if (rchText.SelectionFont.Bold)
{
style &= ~FontStyle.Bold;
}
else
{
style |= FontStyle.Bold;
}
rchText.SelectionFont = new Font(rchText.SelectionFont, style);
rchText.Select();
}
[/code]

I want this button (bold function) to work with new richtextboxes created by tripNewpage_Click function.

How to do that?

Sorry for my english.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories