Fill RichTextBox with Get-Content

(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:
<pre class=“lang:ps decode:true”>$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:
<pre class=“crayon-selected”>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 :slight_smile:

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.

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

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!

In some cases you might need to include some nr 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 :wink: