Back to Blog
Rich text file5/10/2023 ![]() ' Set the file name to myText.Introduced and documented by Microsoft, the Rich Text Format ( RTF) represents a method of encoding formatted text and graphics for use within applications. ' or overwrite the file if it does exist. ' prompted to create the file if it doesn't exist ' Set the properties on SaveFileDialog1 so the user is Private Sub Button2_Click(ByVal sender As Object, _īyVal e As EventArgs) Handles Button2.Click ' Shows the use of a SaveFileDialog to save a MemoryStream to a file. RichTextBox2.LoadFile(userInput, RichTextBoxStreamType.PlainText) ' by setting its position to 0, to RichTextBox2. ![]() ' Display the entire contents of the stream, RichTextBox1.SaveFile(userInput, RichTextBoxStreamType.PlainText) Private Sub Button1_Click(ByVal sender As Object, _īyVal e As EventArgs) Handles Button1.Click ' Save the content of RichTextBox1 to the memory stream, appending Me.Button2.Location = New Point(104, 200) Me.RichTextBox2.Text = "It will be added to the stream and appear here." Me.RichTextBox2.Location = New Point(152, 64) Me.RichTextBox1.Text = "Type something here." Me.RichTextBox1.Location = New Point(24, 64) Set the memoryStream.Position value to 0įriend WithEvents RichTextBox1 As RichTextBoxįriend WithEvents RichTextBox2 As RichTextBoxįriend WithEvents SaveFileDialog1 As SaveFileDialog Open the file, copy the contents of memoryStream to fileStream, "Text files (*.txt)|*.txt|All files (*.*)|*.*" Įnvironment.GetFolderPath() ĭialogResult result = SaveFileDialog1.ShowDialog() Private void Button2_Click(Object sender, EventArgs e) Private void Button1_Click(Object sender, EventArgs e) MemoryStream userInput = new MemoryStream() "It will be added to the stream and appear here." This.SaveFileDialog1 = new SaveFileDialog() which indicates that the file was saved.ĭialogResult result = SaveFileDialog1->ShowDialog() įileStream = SaveFileDialog1->OpenFile() Call ShowDialog and check for a return value of DialogResult.OK, SaveFileDialog1->Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*" Įnvironment->GetFolderPath(Environment::SpecialFolder::MyDocuments) the filter box and no extension is specified by the user. DefaultExt is only used when "All files" is selected from to text files, and set the initial directory to the Set the file name to myText.txt, set the type filter or overwrite the file if it does exist. prompted to create the file if it doesn't exist Set the properties on SaveFileDialog1 so the user is Void Button2_Click( Object^ /*sender*/, EventArgs^ /*e*/ ) Shows the use of a SaveFileDialog to save a MemoryStream to a file. RichTextBox2->LoadFile( userInput, RichTextBoxStreamType::PlainText ) by setting its position to 0, to RichTextBox2. Display the entire contents of the stream, RichTextBox1->SaveFile( userInput, RichTextBoxStreamType::PlainText ) Void Button1_Click( Object^ /*sender*/, EventArgs^ /*e*/ ) Save the content of RichTextBox1 to the memory stream, This->Controls->Add( this->RichTextBox1 ) ![]() This->Controls->Add( this->RichTextBox2 ) Gcnew EventHandler( this, &Form1::Button2_Click ) This->Button2->Text = "Save Stream To File" This->RichTextBox2->Text = "It will be added to the stream " This->RichTextBox2->Name = "RichTextBox2" This->RichTextBox2->Location = Point( 152, 64 ) Gcnew EventHandler( this, &Form1::Button1_Click ) This->Button1->Location = Point( 96, 16 ) This->RichTextBox1->Text = "Type something here." This->RichTextBox1->Name = "RichTextBox1" This->RichTextBox1->Location = Point( 24, 64 ) This->SaveFileDialog1 = gcnew SaveFileDialog This is a complete example that is ready to run when you copy it to your project. It also demonstrates using the FileDialog.FileName, FileDialog.DefaultExt, SaveFileDialog.CreatePrompt, and SaveFileDialog.OverwritePrompt members. The following code example demonstrates using the SaveFile and LoadFile methods with streams. An error occurs in saving the contents of the control to a file.
0 Comments
Read More
Leave a Reply. |