Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Adding color to a RichTextBox

$
0
0

So I have a RichTextBox and I want to colorize individual lines.  The 3 lines I have now are

Red

Green

Blue

So, I want Red to be in Red text, Green in green text, and Blue to be in Blue text.  I have written a basic script.  However when I run it I still get Red, Green, and Blue on seperate lines however they are all still in Black text with an error stating "the term 'color.red' is not recognized as the name of a cmdlet, function..........." <-- I'm sure you all know the rest of the error

If anyone could help, I would really appreciate it.  So here is the code I have...

#Generated Form Function
function GenerateForm {
########################################################################
# Code Generated By: SAPIEN Technologies PrimalForms (Community Edition) v1.0.10.0
# Generated On: 7/23/2013 2:38 PM
# Generated By: 
########################################################################

#region Import the Assemblies
[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
#endregion


#region Generated Form Objects
$form1 = New-Object System.Windows.Forms.Form
$richTextBox1 = New-Object System.Windows.Forms.RichTextBox
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
#endregion Generated Form Objects

#region Generated Form Code
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 262
$System_Drawing_Size.Width = 284
$form1.ClientSize = $System_Drawing_Size
$form1.DataBindings.DefaultDataSourceUpdateMode = 0
$form1.Name = "form1"
$form1.Text = "Primal Form"

$richTextBox1.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 19
$System_Drawing_Point.Y = 19
$richTextBox1.Location = $System_Drawing_Point
$richTextBox1.Name = "richTextBox1"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 225
$System_Drawing_Size.Width = 245
$richTextBox1.Size = $System_Drawing_Size
$richTextBox1.TabIndex = 0
$winuprem = "Red"
$richTextbox1.selectedtext = $winuprem
$richtextbox1.selectionbackcolor = color.red 
$richTextBox1.text = "$winuprem" + "`n"
$richTextBox1.text += "White" + "`n"
$richTextBox1.text += "Blue" + "`n"
$form1.Controls.Add($richTextBox1)

#endregion Generated Form Code

#Save the initial state of the form
$InitialFormWindowState = $form1.WindowState
#Init the OnLoad event to correct the initial state of the form
$form1.add_Load($OnLoadForm_StateCorrection)
#Show the Form
$form1.ShowDialog()| Out-Null

} #End Function

#Call the Function
GenerateForm


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>