How to remove 'System.Windows.Forms.TextBox, Text:' from message and text

13,668

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.

Share:
13,668
Admin
Author by

Admin

Updated on June 04, 2022

Comments

  • Admin
    Admin almost 2 years

    I have written a simple program in C# in which

    1. messages are displayed using a statement like:
        {
         MessageBox.Show("Enter the Correct Values. ", "Error", 
                         MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
         return;
        }
    
    1. 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:

    2. 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
    David Merriman about 12 years
    I'm glad it helped. You should click the check next to this answer to mark it as correct.