Well, your first order of business is to remember which text boxOk, I have a question what would I use if I wanted to do something like a paste function in a Rich Text Box using the code on that thread?
corresponds to which file. There are lots of ways to do this, but what
is probably the easiest way is to use a Hashtable.
I don't know what version of .NET you're using. I'm still on 1.1, so I
apologize in advance if there's a cleaner way to do this in 2.0 using
generics. That said, here is a simple hashtable solution.
Add a using statement to your .cs file for collections:
using System.Collections;
At the top of your Form class definition, where the class members for
the controls are defined, add a new definition for a hash table:
private Hashtable _richTextBoxToFileName;
In your constructor, after the InitializeComponents() call, add a line
to create the hash table:
this._richTextBoxToFileName = new Hashtable();
Now, as you create each RichTextBox by reading a file, just store the
file name in the hash table, using the name of the rich text box as a
key. Every control has a Name property, and every Name on a form has to
be unique, so this will work fine. Let's say that you have a reference
to the new rich text box you added in the variable richBox, and that
you have the name of the file that you loaded in the variable fileName.
Just after you load the text box with the file contents (or before, it
doesn't really matter), do this:
this._richTextBoxToFileName[richBox.Name] = fileName;
Now, any time you have a rich text box and need to know which file to
save to, just do it like this:
string fileNameToSave =
(string)this._richTextBoxToFileName[richTextBoxBeingSaved.Name];
which will get you back the name of the file corresponding to the rich
text box.
There are, of course, other more sophisticated schemes, but this one
has the advantage of being easy to understand.
Hope this helps.
Thanks, Ajm113.