473,394 Members | 1,694 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,394 software developers and data experts.

Saving text from new richTextBox

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 openFile()
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Title = "Select a Text File";

if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
StreamReader sr = new
StreamReader(openFileDialog1.FileName);
string title =
Path.GetFileName(openFileDialog1.FileName);
TabPage myTabPage = new TabPage(title);
tabControl1.TabPages.Add(myTabPage);
int index = tabControl1.TabPages.IndexOf(myTabPage);

//Add the RichTextBox to the tabPage.
NumberedTextBox.NumberedTextBoxUC textBox = new
NumberedTextBox.NumberedTextBoxUC();

this.textBox.richTextBox1 = new
System.Windows.Forms.RichTextBox();

// Load the contents of the file into the RichTextBox.
textBox.richTextBox1.LoadFile(openFileDialog1.File Name,
RichTextBoxStreamType.PlainText);
this.tabControl1.TabPages[index].Controls.Add(textBox);

// Active tabPage is the new tabPage.
this.tabControl1.SelectedTab = myTabPage;

sr.Close();

So the file i want to save is the loaded contens of
textBox.richTextBox1. The save funktion i made(doesn't work) looks like
this:

private void saveFile()
{

// Create a SaveFileDialog to request a path and file name
to save to.
SaveFileDialog saveFile1 = new SaveFileDialog();

// Initialize the SaveFileDialog to specify the extension
for the file.
saveFile1.FileName = tabControl1.SelectedTab.Text;
saveFile1.DefaultExt = "*.pon";
saveFile1.Filter = "Point (*.pon)|*.pon|Luna
(*.lun)|*.lun";

// Determine if the user selected a file name from the
saveFileDialog.
if (saveFile1.ShowDialog() ==
System.Windows.Forms.DialogResult.OK &&
saveFile1.FileName.Length > 0)
{
// Save the contents of the RichTextBox into the file.
this.boxen.richTextBox1.SaveFile(saveFile1.FileNam e,
RichTextBoxStreamType.PlainText);

Feb 7 '06 #1
0 2360

This thread has been closed and replies have been disabled. Please start a new discussion.

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: David Johnston | last post by:
I am converting to the .NET platform and I am starting with C#. Just for exercise I'm writing a text editor and I am having some problems with saving files. I am using a single document...
3
by: kangoo | last post by:
Hi, I'm trying to remove the last charater in a richTextBox. I though richTextBox.Text.Remove(richTextBox.Text.length-1, 1); would work, but it does nothing (eg richTextBox.Text += "some new...
2
by: Martin Dew | last post by:
I have a RichTextBox called rtbOutput. I am adding lines of text using the AppendText method. What I want to do is immediately after adding this line of text make sure that this line of text is...
4
by: JRB | last post by:
Hi, I've got a bunch of text put onto a richTextBox with a StreamWriter. Every now and then I insert a '\n' character for a new line. It displays properly in the richTextBox with the \n character...
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...
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...
0
Ajm113
by: Ajm113 | last post by:
Contributing To: Saving RichTextBox from Tab Control 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?...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.