Windows Develop Bookmark and Share   
 index > Windows Forms General > How to add a new line inside a textfield...
 

How to add a new line inside a textfield...

Ok i'm trying to add a file list into a text field so i can cut and paste... I don't want the file list to be in one continues line, so I'm appending "\n" to the end...  

This works BUT I get the new line character displayed on my screen as well...

this is my code

foreach(object i in this.checkedListBox1.CheckedItems)
{
     Ezcp.textBox1.AppendText("\\blast\\" + i.ToString() + "\n");
}

Is there any other way to create a new line other than using "\n" ??

(I can't reproduce the "new line" character on this post...)

thanks
MigrationUser 1  Friday, January 23, 2004 1:41 PM
i think you have to use \r\n instead of just \n (it could be \n\r not too sure).  

Make sure multiline is set to true otherwise it won't work.
MigrationUser 1  Friday, January 23, 2004 3:51 PM
Use -  Environment.NewLine

As in :

String s = "Hey" + Environment.NewLine + "Im on the next line";
MigrationUser 1  Friday, January 23, 2004 4:03 PM
Hey, another one for you too. Instead of a constant for the directory separator char ("\\")you can use this:

Path.DirectorySeparatorChar


StringBuilder sb = new StringBuilder();

foreach(object i int this.checkedListBox1.CheckedItems)
{
   sb.Length = 0;
   sb.AppendFormat("{0}blast{1}{2}{3}", 
        Path.DirectorySeparatorChar, 
        Path.DirectorySeparatorChar, 
        i.ToString(), 
        Environment.NewLine);

    Ezcp.textBox1.AppendText(sb.ToString());
}
MigrationUser 1  Friday, January 23, 2004 4:07 PM
try \r\n and be sure you have a multiline set to true for the textbox.
MigrationUser 1  Friday, January 23, 2004 5:00 PM
Is it \n\r or \r\n -- I think one of these two take care of the problem.

I current don't use either one anymore. I use the Environment.NewLine property since it will work without thought.


Ezcp.textBox1.AppendText("\\blast\\" + i.ToString() + Environment.NewLine); 
MigrationUser 1  Friday, January 23, 2004 5:59 PM
Environment.Newline will append "\r\n" for you, or whatever the equivalent is for the OS the application is running on.

As for the newline character, a little square box I imagine, try setting the multiline property to true and assigning the text you wish to display to the TextBox.Lines property.  It takes a string array so you may have to do a little string manipulation first.
MigrationUser 1  Friday, January 23, 2004 7:59 PM

yes that little square keeps showing up at the end of each string (path) ...  I'm going to try the suggestions from above tomorrow at work...

Thank you everyone!! :)

MigrationUser 1  Monday, January 26, 2004 1:59 AM

\r\n  worked!!!

Thanks :)
MigrationUser 1  Monday, January 26, 2004 3:11 PM

You can use google to search for other answers

Custom Search

More Threads

• textbox validation
• Displaying Lookup Values in a DataGridView instead of Foreign key's
• How To Set Default PrinterResolution for PageSetupDialog in .NET 2
• Saving a control Region
• Treeview drag & Drop Termination
• How To Call Mdi Function From Dialog Form ?
• Navigating Forms
• ListBox ClearSelected and SelectedIndex = -1 not working?
• Please Please Help
• XML resource is not copying to the "Resources" folder on deployment.