none
Preserve line breaks in textbox RRS feed

  • Question

  • Hi Guys,

     This is probably something that is very simple to do, but how to we get PowerShell to preserve line breaks for text typed into PowerShell textboxes?

    Thanks

    Sunday, December 16, 2018 3:44 PM

Answers

  • The OutOfOffice message is HTML.  Line breaks are no effective in HTML.  They just do nothing.

    -ExternalMessage

    The ExternalMessage parameter specifies the Automatic Replies message that's sent to external senders or senders outside the organization. If the value contains spaces, enclose the value in quotation marks (").

    HTML tags are automatically added to the text. For example, if you enter the text, "I'm on vacation", the value automatically becomes: <html><body>I'm on vacation</body></html>. Additional HTML tags are supported if you enclose the value in quotation marks. For example, "<html><body>I'm on vacation.<br>I'll respond when I return.</body></html>".

    The value of this parameter is meaningful only when both of the following conditions are true:

    • The AutoReplyState parameter is set to Enabled or Scheduled.

    • The ExternalAudience parameter is set to Known or All.

    To clear the value of this parameter when it's no longer required (for example, if you change the ExternalAudience parameter to None), use the value $null.


    \_(ツ)_/

    • Marked as answer by sabedin77 Thursday, December 20, 2018 6:23 PM
    Wednesday, December 19, 2018 7:20 PM

All replies

  • What PowerShell textboxes?  PowerShell does not have textboxes.  What does "preserve" mean?


    \_(ツ)_/


    • Edited by jrv Sunday, December 16, 2018 4:53 PM
    Sunday, December 16, 2018 4:52 PM
  • If you are asking about Windows forms then you need to set the textbox to "multiline"

    $textbox.Multiline =  $true

    https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.textbox.multiline?view=netframework-4.7.2


    \_(ツ)_/

    Sunday, December 16, 2018 6:17 PM
  • Thanks already done that.


    So I am taking my text using $x = $textBox.Text

    Have also tried $x = $textBox.Lines

    If I input the below in text box:

    Line 1

    Line 2

    It outputs:

    Line 1 Line 2

    I need the two lines to output as I typed them.



    • Edited by sabedin77 Monday, December 17, 2018 7:07 PM
    Monday, December 17, 2018 7:07 PM
  • Output?  What is output?  Forms do not have output.

    There is no way to answer because your question is too vague.

    If you type lines into a multiline textbox then the "Lines" property has an array of the lines you typed.


    \_(ツ)_/

    Monday, December 17, 2018 7:20 PM
  • What I am trying to do is use the texbox input to write text into a mailboxes's out of office.

    I would like the lines to be kept separate as I type them into the text box but this does not happen.

    Monday, December 17, 2018 7:35 PM
  • If it is a multiline textbox then the enter key will create separate lines.  Why do you think this is not true?


    \_(ツ)_/

    Monday, December 17, 2018 7:45 PM
  • Run the following to see the output is a set of lines.  When displayed type in lines with an enter key after each line.

    $form = New-Object System.Windows.Forms.Form
    Add-Type -AssemblyName System.Windows.Forms
    $form = New-Object System.Windows.Forms.Form
    $textbox = New-Object System.Windows.Forms.Textbox
    $form.Controls.Add($textbox)
    $textbox.MultiLine = $true
    $textbox.Dock = 'Fill'
    $form.ShowDialog()
    $textbox.Lines


    \_(ツ)_/


    • Edited by jrv Monday, December 17, 2018 7:52 PM
    Monday, December 17, 2018 7:51 PM
  • Here is a more explicit example:

    Add-Type -AssemblyName System.Windows.Forms
    $form = New-Object System.Windows.Forms.Form
    $form.FormBorderStyle = 'FixedDialog'
    $textbox = New-Object System.Windows.Forms.Textbox
    $form.Controls.Add($textbox)
    $textbox.MultiLine = $true
    $textbox.Width = $form.ClientSize.Width - 20
    $textbox.Height = $form.ClientSize.Height - 20
    $textbox.Location = '10,10'
    $textbox.BackColor = 'LightGreen'
    $form.ShowDialog()
    $textbox.Text > testform.txt
    notepad testform.txt
    


    \_(ツ)_/

    Monday, December 17, 2018 9:52 PM
  • I use Windows Forms with my PowerShell scripts and create executable programs and when I have output string and need a newline in a textbox or richtextbox I use the `n for newline and `t for adding a tab. Hope that helps. The character in `n is the top left of your keyboard under the esc key.
    • Edited by ComputerScott Tuesday, December 18, 2018 10:03 PM
    • Proposed as answer by ComputerScott Tuesday, December 18, 2018 10:03 PM
    Tuesday, December 18, 2018 10:02 PM
  • I use Windows Forms with my PowerShell scripts and create executable programs and when I have output string and need a newline in a textbox or richtextbox I use the `n for newline and `t for adding a tab. Hope that helps. The character in `n is the top left of your keyboard under the esc key.

    This is unnecessary since the textbox in multiline mode automatically enters these characters when the keys are used.  Not sure why you think you need to do this.


    \_(ツ)_/

    Tuesday, December 18, 2018 10:09 PM
  • It is not a case that the textbox itself is not keeping the line breaks but when this is input into Powershell to set OutOfOffice.
    Wednesday, December 19, 2018 7:14 PM
  • The OutOfOffice message is HTML.  Line breaks are no effective in HTML.  They just do nothing.

    -ExternalMessage

    The ExternalMessage parameter specifies the Automatic Replies message that's sent to external senders or senders outside the organization. If the value contains spaces, enclose the value in quotation marks (").

    HTML tags are automatically added to the text. For example, if you enter the text, "I'm on vacation", the value automatically becomes: <html><body>I'm on vacation</body></html>. Additional HTML tags are supported if you enclose the value in quotation marks. For example, "<html><body>I'm on vacation.<br>I'll respond when I return.</body></html>".

    The value of this parameter is meaningful only when both of the following conditions are true:

    • The AutoReplyState parameter is set to Enabled or Scheduled.

    • The ExternalAudience parameter is set to Known or All.

    To clear the value of this parameter when it's no longer required (for example, if you change the ExternalAudience parameter to None), use the value $null.


    \_(ツ)_/

    • Marked as answer by sabedin77 Thursday, December 20, 2018 6:23 PM
    Wednesday, December 19, 2018 7:20 PM
  • Yep - will have to write some extra code into Powershell to get the Out of Office to keep line breaks.

    Thanks for all your assistance on this yet again.

    Thursday, December 20, 2018 6:24 PM
  • Two ways to do this:

    $oom = '<pre style="color:yellow;background-color: teal;font-weight: bolder">' + $textbox.Text + '</pre>'

    and

    $oom = $textbox.Lines | %{"$_ <br/>"} 

    Or just type html tags into the textbox.


    \_(ツ)_/

    Thursday, December 20, 2018 9:41 PM