473,320 Members | 1,858 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Re: Saving RichTextBox from Tab Control

Ajm113
161 100+
Contributing To: Saving RichTextBox from Tab Control

Well, your first order of business is to remember which text box
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.
Ok, 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?

Thanks, Ajm113.
Oct 23 '07 #1
0 1363

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: gogaz | last post by:
Hello, I am facing one strange problem. I am using RichTextBox control in my VB6.0 application and have provided one button giving functionality to set bullets on the selected text. When i type...
1
by: vanvee | last post by:
Hi I have a user control that contains a RichTextBox in vb.net. In my program, I create multiple instances of this control (with the RichTextBox being in each one), that appear one above the...
0
by: AxOn | last post by:
Hi! I'm having trouble creating a save funktion. How can I save the contens of a new richTextBox that is created from an "external" class file? The open funktion looks like this: public void...
8
by: AxOn | last post by:
Hi, How can i save the specific RichTextBox in the selected tab if i have several tabs with RichTextBoxes in? The application is a text editor type program and when i try to save the most...
3
by: AxOn | last post by:
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...
9
by: James Wong | last post by:
Hi, I use the RichTextBox in my program. It will use different language in this RichTextBox (chinese and english characters), and it set the "DualFont" and use different fonts. By the way, how...
3
by: michael sorens | last post by:
The documentation for the RichTextBox is sketchy at best. I want to do a very simple task but I cannot find information on this. I am using a RichTextBox as an output window. Some text I want to...
4
by: =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post by:
Hello, I have a multiline RichTextBox that I use for data logging. I'm concerned about how the AppendText method reacts when over time the maximum number of characters have been added. Do the...
1
by: =?Utf-8?B?TWFya19C?= | last post by:
I have an unpredictable number of RichTestBoxes, stored in a generic list, that are created at runtime. Currently, I am saving these controls to a file by saving each attribute of each box in...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.