How to remove 'System.Windows.Forms.TextBox, Text:' from message and text
Without seeing your code, I'm guessing you're passing the TextBox
directly to the StreamWriter
, rather than passing the TextBox.Text
property value. Passing the TextBox
reference directly to StreamWriter.WriteLine
will call TextBox.ToString()
to get a string value that it can write, and it looks like TextBox.ToString()
is generating that prefix. Pass in TextBox.Text
, and you shouldn't see it anymore.
Admin
Updated on June 04, 2022Comments
-
Admin almost 2 years
I have written a simple program in C# in which
- messages are displayed using a statement like:
{ MessageBox.Show("Enter the Correct Values. ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; }
Some text box contents are written to text files using StreamWriter. In both case, in addition to the correct content, I also get the prefix: System.Windows.Forms.TextBox, Text:
I get a similar prefix (and a suffix of \r\n) when using StreamReader to read the contents of a text file.
How do I avoid this?
-
David Merriman about 12 yearsI'm glad it helped. You should click the check next to this answer to mark it as correct.