Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Windows Forms
  4. Help textbox

Help textbox

Scheduled Pinned Locked Moved Windows Forms
help
7 Posts 2 Posters 5 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Anka_Ame
    wrote on last edited by
    #1

    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.

    A 1 Reply Last reply
    0
    • A Anka_Ame

      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.

      A Offline
      A Offline
      Arun Immanuel
      wrote on last edited by
      #2

      Read this: Click here

      Regards, Arun Kumar.A

      A 1 Reply Last reply
      0
      • A Arun Immanuel

        Read this: Click here

        Regards, Arun Kumar.A

        A Offline
        A Offline
        Anka_Ame
        wrote on last edited by
        #3

        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?

        A 1 Reply Last reply
        0
        • A Anka_Ame

          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?

          A Offline
          A Offline
          Arun Immanuel
          wrote on last edited by
          #4

          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

          A 1 Reply Last reply
          0
          • A Arun Immanuel

            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

            A Offline
            A Offline
            Anka_Ame
            wrote on last edited by
            #5

            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"); } } } }

            A 1 Reply Last reply
            0
            • A Anka_Ame

              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"); } } } }

              A Offline
              A Offline
              Arun Immanuel
              wrote on last edited by
              #6

              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

              A 1 Reply Last reply
              0
              • A Arun Immanuel

                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

                A Offline
                A Offline
                Anka_Ame
                wrote on last edited by
                #7

                :) It's working to save it only like text. Thanks a lot.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups