How do i load a text file to a windows clr textbox?
and how do i save the lines of the textbox to a file?

Recommended Answers

All 7 Replies

How do i load a text file to a windows clr textbox?

Using a System::IO::StreamReader object and it's ReadToEnd() method. This will give you a String ^ to which you can set your textBox1.Text.

and how do i save the lines of the textbox to a file?

Use a System::IO;:StreamWriter object. It has methods Write() and WriteLine() that you can use just like the Console::Write() and WriteLine() See how far you get with that and post back if you need more information.

Thank you very much

The reading of the file went well but when i need to save the file i get a An unhandled exception of type 'System.IndexOutOfRangeException' occurred] My code looks like this :

StreamWriter^ outfile = gcnew StreamWriter("fffffff.ini");
		 textBox2->Lines[linesuckup.linenum]="[textline1]="+textBox1->Text;
		 outfile->Write(textBox2->Lines);
        outfile->Close();

I dont understand how i am getting this error and whats causing it, to my appearance everything seems fine and logical.

Something is wrong with your linesuckup.linenum value. Where is that coming from? Check it versus textBox2->Lines->Count .

[edit]Problem solved, thank you all who helped me.

Something is wrong with your linesuckup.linenum value. Where is that coming from? Check it versus textBox2->Lines->Count .

Yep you were right now that thats fixed i notice that i cant change my lines :S
this line of my code isn like this :

textBox4->Text=textBox3->Text;
textBox4->Lines[4]=textBox4->Lines[4]->Replace(textBox4->Lines[4],"succes");

The code looks ok to me but textbox4 line 4 doesnt change to "Succes".

The code looks ok to me but textbox4 line 4 doesnt change to "Succes".

I was having some deja vu as I believe I have helped you with this last issue before:
http://www.daniweb.com/forums/thread261339.html
Even though Lines is technically read/write it seems as if you have to write via setting it equal to a "gcnew'd" array.

I was having some deja vu as I believe I have helped you with this last issue before:
http://www.daniweb.com/forums/thread261339.html
Even though Lines is technically read/write it seems as if you have to write via setting it equal to a "gcnew'd" array.

Hahahaha, i knew someone solved that problem for me and when i took a second look in my old post's i saw the fix and edited my post :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.