Help textbox
-
Please help me. I want to save some words which I enter into a textbox in an output file *.txt. If you can help me, please do it.
Read this: Click here
Regards, Arun Kumar.A
-
Read this: Click here
Regards, Arun Kumar.A
if ((myStream = sfd->OpenFile()) != nullptr) { try { StreamWriter^ txtWriter; txtWriter = gcnew System::IO::StreamWriter(filename); txtWriter->Write(textOutput->Text); txtWriter = nullptr; textOutput->SelectionStart=0; textOutput->SelectionLength=0; txtWriter->Close(); myStream->Close(); } } This is something that I tried. My problem is that it doesnt save anything and it gives me a error message like "The file can not be saved because it's in use by another application". What can I do?
-
if ((myStream = sfd->OpenFile()) != nullptr) { try { StreamWriter^ txtWriter; txtWriter = gcnew System::IO::StreamWriter(filename); txtWriter->Write(textOutput->Text); txtWriter = nullptr; textOutput->SelectionStart=0; textOutput->SelectionLength=0; txtWriter->Close(); myStream->Close(); } } This is something that I tried. My problem is that it doesnt save anything and it gives me a error message like "The file can not be saved because it's in use by another application". What can I do?
R U trying this in the Text_change Event. I think U R opening the file again before it is closed. Or Can U post the entire code?
Regards, Arun Kumar.A
-
R U trying this in the Text_change Event. I think U R opening the file again before it is closed. Or Can U post the entire code?
Regards, Arun Kumar.A
private: System::Void saveToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) { SaveFileDialog^ sfd = gcnew SaveFileDialog(); sfd->InitialDirectory = "c:\\"; sfd->FilterIndex =2; sfd->Filter = "TSP Files (*.tsp)|*.tsp|All files (*.*)|*.*|XML Files (*.xml)|*.xml|RTF Files (*.rtf)|*.rtf"; sfd->Title = "Save"; sfd->RestoreDirectory = true; if (sfd->ShowDialog() == System::Windows::Forms::DialogResult::OK) { filename = sfd->FileName; if ((myStream = sfd->OpenFile()) != nullptr) { RichTextBox^ rich = gcnew RichTextBox(); try { String^ strExt; strExt = System::IO::Path::GetExtension(filename); strExt = strExt->ToUpper(); if (strExt == ".RTF") { rich->SaveFile(filename); myStream->Close(); } else { StreamWriter^ txtWriter; txtWriter = gcnew System::IO::StreamWriter(filename); txtWriter->Write(textOutput->Text); txtWriter = nullptr; textOutput->SelectionStart=0; textOutput->SelectionLength=0; txtWriter->Close(); myStream->Close(); } filename = sfd->FileName; this->Text = "Editor: " + filename->ToString(); MessageBox::Show(filename->ToString() + " saved.", "File Save"); } catch (Exception^ e) { MessageBox::Show(e->Message->ToString(), "File Save Error"); } } } }
-
private: System::Void saveToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) { SaveFileDialog^ sfd = gcnew SaveFileDialog(); sfd->InitialDirectory = "c:\\"; sfd->FilterIndex =2; sfd->Filter = "TSP Files (*.tsp)|*.tsp|All files (*.*)|*.*|XML Files (*.xml)|*.xml|RTF Files (*.rtf)|*.rtf"; sfd->Title = "Save"; sfd->RestoreDirectory = true; if (sfd->ShowDialog() == System::Windows::Forms::DialogResult::OK) { filename = sfd->FileName; if ((myStream = sfd->OpenFile()) != nullptr) { RichTextBox^ rich = gcnew RichTextBox(); try { String^ strExt; strExt = System::IO::Path::GetExtension(filename); strExt = strExt->ToUpper(); if (strExt == ".RTF") { rich->SaveFile(filename); myStream->Close(); } else { StreamWriter^ txtWriter; txtWriter = gcnew System::IO::StreamWriter(filename); txtWriter->Write(textOutput->Text); txtWriter = nullptr; textOutput->SelectionStart=0; textOutput->SelectionLength=0; txtWriter->Close(); myStream->Close(); } filename = sfd->FileName; this->Text = "Editor: " + filename->ToString(); MessageBox::Show(filename->ToString() + " saved.", "File Save"); } catch (Exception^ e) { MessageBox::Show(e->Message->ToString(), "File Save Error"); } } } }
Please do the following changes and let me know if it works: else { myStream->Close(); //Insert this line StreamWriter^ txtWriter; txtWriter = gcnew System::IO::StreamWriter(filename); txtWriter->Write(textOutput->Text); txtWriter = nullptr;//Remove this line.
Regards, Arun Kumar.A
-
Please do the following changes and let me know if it works: else { myStream->Close(); //Insert this line StreamWriter^ txtWriter; txtWriter = gcnew System::IO::StreamWriter(filename); txtWriter->Write(textOutput->Text); txtWriter = nullptr;//Remove this line.
Regards, Arun Kumar.A