Author Posts

June 1, 2013 at 10:00 am

(OK, I managed to add content to my thread... the site doesn't seem to function in FF 21.0... IE works)

I'm creating a GUI application, an offline UBB text editor, with Powershell. I'm new to GUI development and struggling with getting my content into a RichTextBox.

What I do right now is:

$smnuOpen_Click = {$dlgOpen.ShowDialog() ; $txtEditor.Text = (Get-Content $dlgOpen.FileName)}

The content is indeed put into my RichTextbox, but returns have been lost.

If my input is

Foo
Bar

The RichTextBox will show:

FooBar

Tabs are not a problem on the other hand. Anyone knows a solution for this? Keeping the formatting is quite essential to my application 🙂

June 1, 2013 at 10:14 am

We don't support the "code" bb tags. You're meant to use the <> button in the toolbar to paste code.

Get-Content doesn't read your text as a single string. It parses the text, and essentially splits the file on CRLF. Each line in the file thus becomes a System.String object. When you set the RTB it's probably calling ToString() on those, which won't produce CRLFs.

Try doing something like gc filename.txt | Out-String to force the shell to produce a single string for you.

June 1, 2013 at 10:15 am

(oh, and I use the site almost exclusively in FF 21.0, FWIW).

June 1, 2013 at 10:20 am

Hi Don. I feel like God is talking to me right now.
I noticed about the [code]-tags. The crayon-method doesn't seem to like me either though ^^

Most importantly: your suggestion was spot on. It works like a charm. Thank you very, very much!

June 3, 2013 at 3:56 am

In some cases you might need to include some `n`r in your strings to force a CRLF.
Some times I find I need both and some times either of them is enough on its own.

However, where you can use it, Don's method is preferable as it will respect the CRLFs that are already in the source 😉