I have a text editor program I am making, where a new tab page is added to a tab control every time the user clicks a specific button. A Rich Text Box Control is added to each new tab page that is created, and I need to be able to save the text from the Rich Text Box Control that is on the currently selected tab page when the user clicks another button. Does anyone know how
I'm not sure if this has been asked before, but can't seem to find a soloution (I'm only a beginner).
I add a new tab page with this code:
private void toolNew_Click(object sender, EventArgs e){
RichTextBox newText = new RichTextBox();string title = "New " + (tabControl.TabCount + 1).ToString();
TabPage newTabPage = new TabPage(title);
tabControl.TabPages.Add(newTabPage);
tabControl.SelectedTab = newTabPage;
newTabPage.Controls.Add(newText);
}
Hope that helps, please, if anyone knows how to solve this, tell me, thanks in advance.

Saving from a RichTextBox control in the selected TabPage
e.henriquez
You need to do something like this:
RichtextBox newRichTextBox = tabControl.SelectedTab.Controls[0] as RichTextBox; //Suppose RichtextBox was first control added to the new TabPage.
if(newRichTextBox != null)
newRichTextBox.SaveFile("C:\\filename.rtf", RichTextBoxStreamType.RichText);
I hope it'll work!
Cheers ;-)
Donal McWeeney
Yes, it seems to have worked, the code I put in under the save button's click event was:
RichTextBox tempbox = tabControl.SelectedTab.Controls[0] as RichTextBox;
// I have a save file dialog on my form
if (saveFile.ShowDialog() == DialogResult.OK)
tempbox.SaveFile(saveFile.FileName, RichTextBoxStreamType.PlainText);
Thanks! I really needed to know how to do this!
mahima
Hi,
according to your code, each time you when you click on, you generate a new local RichTextBox newText (RichTextBox newText = new RichTextBox();) . That mean it can't stay available by the next click! So you can try to define it as global in your class. If you need moore help on the subject, please write a small class to explain correct your problem.
I hope it can help