473,657 Members | 2,566 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 (openFileDialog 1.ShowDialog() == DialogResult.OK )
{
StreamReader sr = new
StreamReader(op enFileDialog1.F ileName);
string title =
Path.GetFileNam e(openFileDialo g1.FileName);
TabPage myTabPage = new TabPage(title);
tabControl1.Tab Pages.Add(myTab Page);
int index = tabControl1.Tab Pages.IndexOf(m yTabPage);

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

this.textBox.ri chTextBox1 = new
System.Windows. Forms.RichTextB ox();

// Load the contents of the file into the RichTextBox.
textBox.richTex tBox1.LoadFile( openFileDialog1 .FileName,
RichTextBoxStre amType.PlainTex t);
this.tabControl 1.TabPages[index].Controls.Add(t extBox);

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

sr.Close();

So the file i want to save is the loaded contens of
textBox.richTex tBox1. 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.FileN ame = tabControl1.Sel ectedTab.Text;
saveFile1.Defau ltExt = "*.pon";
saveFile1.Filte r = "Point (*.pon)|*.pon|L una
(*.lun)|*.lun";

// Determine if the user selected a file name from the
saveFileDialog.
if (saveFile1.Show Dialog() ==
System.Windows. Forms.DialogRes ult.OK &&
saveFile1.FileN ame.Length > 0)
{
// Save the contents of the RichTextBox into the file.
this.boxen.rich TextBox1.SaveFi le(saveFile1.Fi leName,
RichTextBoxStre amType.PlainTex t);

Feb 7 '06 #1
0 2382

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

Similar topics

0
1890
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 and set bullets on some text and save the document, it is displaying everything ok. But when i open the saved file again I notice some small dots in the line before and after the bulleted text.
1
1337
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 interface system. I am just working with plain text now but I was wondering what differences I would have to make to save between .txt, .rtf, or even .doc if possible. Thanks for any help you could give or examples you could point me to . Thanks again.
3
21118
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 text"; works) Thanks for your attention & solutions
2
3996
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 displayed, effictively scrolling to the last line of the text box all the time. Can anyone help as I cannot seem to find a way to do this. Thanks
4
7536
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 moving the text down to the next line. The problem is that I have it set up so when the user clicks a button I want to be able to save everything on the richTextBox to a file. It works properly, but when I view the text file with Notepad, the \n...
8
3261
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 recently opened text file in the rich text box my application saves that file over the other files?? Can i some how index the new RichTextBoxes so that only the text in the selected RichTextBox is saved??
3
2180
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 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:
3
7172
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 just add plain (e.g.. rtf.Text += "new stuff..."; ) but some text, when added, I want to be in a different color or font size. Find() will not work because the text will vary. I have delimiters on it so I could recognize it with a regular ...
0
1390
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? Thanks, Ajm113.
0
8392
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8305
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8732
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8605
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7324
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6163
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4151
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4302
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1611
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.