Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.


Taking RTF multiline input and converting to html

Taking RTF multiline input and converting to html

Hi all - I'm trying to change a powershell script that took a single line console input and used it to set something that accepts HTML so that it has a richtextbox for input that accepts multiline text (this much works ok) but preferably that has a way to convert it to HTML. So far I've said


$text = $text -replace "`r`n", "<br>" 
which successfully turns the newlines into linebreaks - but it would be nice to keep all the formatting of what is pasted in rather than making it all plain black etc.
Also I noticed that when copying in my email signature, it would turn something like


where the email address was coloured red and a hyperlink to the email


Email: <> 
where the email and the hyperlink code are red
Obviously if this was going to me a correct conversion to html it would be


Email: <></a> 
and code for font colour too
I'm sure there must be a simple way to do this as people must want to take HTML code from people based on richtextbox input?
Using this form currently


function Read-MultiLineInputDialog([string]$Message, [string]$WindowTitle, [string]$DefaultText)
	$inputText = Read-MultiLineInputDialog -Message "If you have a really long message you can break it apart`nover two lines with the powershell newline character:" -WindowTitle "Window Title" -DefaultText "Default text for the input box."
	Shows how to break the second parameter (Message) up onto two lines using the powershell newline character (`n).
	If you break the message up into more than two lines the extra lines will be hidden behind or show ontop of the TextBox.
	Name: Show-MultiLineInputDialog
	Author: Daniel Schroeder (originally based on the code shown at
	Version: 1.0
	Add-Type -AssemblyName System.Drawing
	Add-Type -AssemblyName System.Windows.Forms
	# Create the Label.
	$label = New-Object System.Windows.Forms.Label
	$label.Location = New-Object System.Drawing.Size(10,10) 
	$label.Size = New-Object System.Drawing.Size(280,20)
	$label.AutoSize = $true
	$label.Text = $Message
	# Create the RichTextBox used to capture the user's text.
	$richTextBox1 = New-Object System.Windows.Forms.RichTextBox
	$richTextBox1.Anchor = 15
	$richTextBox1.DataBindings.DefaultDataSourceUpdateMode = 0
	$System_Drawing_Point = New-Object System.Drawing.Point
	$System_Drawing_Point.X = 10
	$System_Drawing_Point.Y = 40
	$richTextBox1.Location = $System_Drawing_Point
	$richTextBox1.Name = "richTextBox1"
	$System_Drawing_Size = New-Object System.Drawing.Size
	$System_Drawing_Size.Height = 200
	$System_Drawing_Size.Width = 575
	$richTextBox1.Size = $System_Drawing_Size
	$richTextBox1.TabIndex = 2
	$richTextBox1.Text = ""
	$richTextBox1.font = "Arial"

	# Create the OK button.
	$okButton = New-Object System.Windows.Forms.Button
	$okButton.Location = New-Object System.Drawing.Size(415,250)
	$okButton.Size = New-Object System.Drawing.Size(75,25)
	$okButton.Text = "OK"
	$okButton.Add_Click({ $form.Tag = $richTextBox1.Text; $form.Close() })
	# Create the Cancel button.
	$cancelButton = New-Object System.Windows.Forms.Button
	$cancelButton.Location = New-Object System.Drawing.Size(510,250)
	$cancelButton.Size = New-Object System.Drawing.Size(75,25)
	$cancelButton.Text = "Cancel"
	$cancelButton.Add_Click({ $form.Tag = $null; $form.Close() })
	# Create the form.
	$form = New-Object System.Windows.Forms.Form 
	$form.Text = $WindowTitle
	$form.Size = New-Object System.Drawing.Size(610,320)
	$form.FormBorderStyle = 'FixedSingle'
	$form.StartPosition = "CenterScreen"
	$form.AutoSizeMode = 'GrowAndShrink'
	$form.Topmost = $True
	$form.AcceptButton = $okButton
	$form.CancelButton = $cancelButton
	$form.ShowInTaskbar = $true
	# Add all of the controls to the form.
	# Initialize and show the form.
	$form.ShowDialog() > $null	# Trash the text of the button that was clicked.
	# Return the text that the user entered.
	return $form.Tag




RE: Taking RTF multiline input and converting to html

Attached is the difference between pasting html markup copied to the clipboard from the left nav of this website into word vs into my ps script's form rtf textbox.
As you can see the RTF textbox doesn't handle it correctly. Once it does it is being passed to the "set-mailboxautoreplyconfiguration" cmdlet for exchange which accepts HTML not RTF so I think it would need converting? Eitherway for now I'm using a multiline textbox instead and losing all the formatting :/




Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close