Demo of code wrapped in a textarea control


Demo of styled code using code highlighter

#Load Required Assemblies
Add-Type ľassemblyName PresentationFramework
Add-Type ľassemblyName PresentationCore
Add-Type ľassemblyName WindowsBase
[array]$colors = "red","green","black","gray","blue","yellow","purple"

#Build the GUI
[xml]$xaml = @"
<Window
xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
x:Name='Window' Title='Colors' ResizeMode = 'NoResize' WindowStartupLocation = 'CenterScreen'
SizeToContent = 'WidthAndHeight' ShowInTaskbar = 'True'>
<StackPanel>
<TextBlock Text = 'Click the button to change the text below' Foreground = 'Black' TextWrapping = 'Wrap' Width = '150'/>
<Button x:Name = 'Button' Content = 'Push Me' Width = '60'/>
<Label x:Name = 'Label' Content = 'Black' Foreground = 'Black' />
</StackPanel>
</Window>
"
@
$reader=(New-Object System.Xml.XmlNodeReader $xaml)
$Global:Window=[Windows.Markup.XamlReader]::Load( $reader )
##Connect to Controls
$label = $Window.FindName('Label')
$Button = $Window.FindName('Button')

##Events
#Button Event
$Button.Add_Click({
$color = Get-Random $colors
$label.Content = $color
$label.Foreground = $color
})
$Window.showdialog()