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
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
into
where the email and the hyperlink code are red
Obviously if this was going to me a correct conversion to html it would be
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
_________________________________
Leozack
Code:
$text = $text -replace "`r`n", "<br>"
Also I noticed that when copying in my email signature, it would turn something like
Code:
Email: thisis@myemail.com
into
Code:
Email: thisis@myemail.com <mailto:thisis@myemail.com>
Obviously if this was going to me a correct conversion to html it would be
Code:
Email: <mailto:thisis@myemail.com>thisis@myemail.com</a>
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
Code:
function Read-MultiLineInputDialog([string]$Message, [string]$WindowTitle, [string]$DefaultText)
{
<#
.EXAMPLE
$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.
.NOTES
Name: Show-MultiLineInputDialog
Author: Daniel Schroeder (originally based on the code shown at [URL unfurl="true"]http://technet.microsoft.com/en-us/library/ff730941.aspx)[/URL]
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.
$form.Controls.Add($label)
$form.Controls.Add($richTextBox1)
$form.Controls.Add($okButton)
$form.Controls.Add($cancelButton)
# Initialize and show the form.
$form.Add_Shown({$form.Activate()})
$form.ShowDialog() > $null # Trash the text of the button that was clicked.
# Return the text that the user entered.
return $form.Tag
}
_________________________________
Leozack
Code:
MakeUniverse($infinity,1,42);