Saving dynamically created RichTextBox text

A

AxOn

Hi,

I have an application with a Save function. I want to be able to have
several tabs(each containing a RichTextBox, created at runtime) open in
a tabControl and save the text from each RichTextBox one at a time. The
plain text is loaded into the RichTextBoxes via an openFile funktion
that creates a new RichTextBox. When the file is opened the name of the
new RichTextBox and the name of the file is stored in a Hashtable like
so:

this.boxen.richTextBox1.Name = "box" + this._pageCount.ToString();
this._pageCount += 1;

this._richTextBoxToFileName[this.boxen.richTextBox1.Name] =
openFileDialog1.FileName;

How can I save the contens of the RichTextBox in the selected tabPage.
Can I some how choose the RichTextBox when I know it's name or name the
RichTextBox that i want to save at runtime??

Thanks!
 
T

the.duckman

ritch text boxes expose a feilt called "rtf".
The text in this feild is stores all the rich text in the controll.

also your richtextbox has load and save functions...

-dm
 
A

AxOn

The text that is loaded into the RichTextBoxes is
RichTextBoxStreamType.PlainText. The problem is that my save function
doesn't recognize which tab containing one of the RichTextBoxes is
selected. When I try to save the text like this, my save function saves
the RichTextBox that was opened last, and not he one in the
selectedTab.

this.boxen.richTextBox1.SaveFile(fileNameToSave,
RichTextBoxStreamType.PlainText) ;

I do know wich is selected by doing the following:

string fileNameToSave =
(string)this._richTextBoxToFileName[tabControl1.SelectedTab.Name];

So, how do I save the text from the selected tabPage??
 
T

the.duckman

This is all of memory so don't shot me if there is a problem.

your tab box control has a "selectedtab" property. Its a reference to
the currently selected tab page. This items has a "controls"
collection. This stores all the controls in the tab.

so something like...

foreach (control c in myTabControl.selectedtab.controls)
if(c is richTextBx)
((richtextbox)c).save(....)


note the above code is just mey thyping out roughly for you it is not
syntaticly correct and you will need to sort it out yourself to make it
compile.....

Hope this helps

-dm
 

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