Adding new line character to string using TextBox contol (CF)

G

Guest

Hi. I've a rather newbie question:

I'm concatenating several strings, adding "\n" where necessary, and setting
the final string to the text property of a multi-line textBox control.
However, instead of generating new lines, wierd symbols appear in the
textBox. I'm developing using .NET CF for PPC.

What am i neglecting to do to properly format my string?

Thanks,
 
J

Jon Skeet [C# MVP]

charliewest said:
Hi. I've a rather newbie question:

I'm concatenating several strings, adding "\n" where necessary, and setting
the final string to the text property of a multi-line textBox control.
However, instead of generating new lines, wierd symbols appear in the
textBox. I'm developing using .NET CF for PPC.

What am i neglecting to do to properly format my string?

Use "\r\n" instead of "\n".
 
R

Rakesh Rajan

Hi Charlie,

Use the Environment.NewLine property. Its a constant for "\r\n" which
depends on the current platform.

HTH,
Rakesh Rajan
 
J

Jon Skeet [C# MVP]

Rakesh Rajan said:
Use the Environment.NewLine property. Its a constant for "\r\n" which
depends on the current platform.

It depends on the current platform, but there's no guarantee that the
default new line for the platform will be the one used for text boxes.
Consider Windows Forms via Mono - should that use \r\n or \n? For
compatibility with other Windows programs, it should use \r\n (and if
you're using WINE, that's what I'd imagine it would use) whereas the
new line for the Linux platform as a whole is \n.

Personally I'd use Environment.NewLine for writing to text files, but
that's all.
 
R

Rakesh Rajan

Hi Jon,

Just wondering: shouldn't the default new line for the platform be the one
used for controls as well?

Are you trying to say that in different platforms this is not the case?

Regards,
Rakesh Rajan
 
J

Jon Skeet [C# MVP]

Rakesh Rajan said:
Just wondering: shouldn't the default new line for the platform be the one
used for controls as well?

It might be, but I don't think there's any guarantee - especially if
the UI toolkit you're using is one which is really designed for a
different platform (eg using Windows Forms under Mono, possibly via
WINE).
Are you trying to say that in different platforms this is not the case?

I'm saying it *might* not be the place. It's unfortunate that TextBox
doesn't have its own NewLine property, IMO.
 
R

Rakesh Rajan

Hi Jon,

Hmm...I think that some kind of a standard should be in place for people
developing UI toolkits. Wonder if MS has published anything of that sort.

Regards,
Rakesh Rajan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top