Hi,

I'm having problem with "WriteLine". What I'm tryin to do is write into the selected txt file(from openFileDialog) when user type something in the textBox.
******************************************************
My output is something wrong. For example: when I type "testing" in the textBox, what I see in my text file is as below:
t
te
tes
test
testi
testin
testing
******************************************************

kindly give me some advice if I'm wrong with the code.

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) 
			 {
				openFileDialog1->ShowDialog();
				
				StreamReader^ sr = gcnew StreamReader(openFileDialog1->FileName); 
				String^ textfile = sr->ReadToEnd();
				sr->Close();
				textBox1->Text= textfile;
}

	private: System::Void textBox2_TextChanged(System::Object^  sender, System::EventArgs^  e) 
			 {
				
				StreamWriter^ writeToFile = File::AppendText(openFileDialog1->FileName);
				//String^ fileName=openFileDialog1->FileName;   //save file directory to txt file
				
				writeToFile->WriteLine(textBox2->Text);
				writeToFile->Close();
			 }

you'll probably get better responses if you post your C++ code in the C++ forum.

It's doing exactly what you asked it to. You're having the program look for when the text has changed in the textbox (so if you type in any characters that event is firing with each one) and outputting the results to the file. You are getting the text of entire textbox written out each time and the entries are being appended after one another.
You need to either wait for the user to press enter or put a "send" button on the window.

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.