Thursday, October 27, 2016

Overlaying big text on the screen with PowerShell

Somebody wanted to use a command-line-invokable script to throw up a massive text overlay on the screen. The easiest way to do that using only built-in Windows tools is, of course, PowerShell.

When this script is run, the word "Hi!" appears in blue on top of everything. It goes away once the text (not the area around it) is clicked.

Add-Type -AssemblyName System.Windows.Forms
$form = New-Object System.Windows.Forms.Form
$form.TransparencyKey = $form.BackColor
$form.WindowState = 'Maximized'
$form.FormBorderStyle = 'None'
$label = New-Object System.Windows.Forms.Label
$label.Font = New-Object System.Drawing.Font ($label.Font.FontFamily, 200)
$label.ForeColor = [System.Drawing.Color]::FromKnownColor('Blue')
$label.AutoSize = $true
$label.Text = 'Hi!'
$label.Add_Click({$form.Close()})
$form.Controls.Add($label)
[Windows.Forms.Application]::Run($form)

It works by creating a standard Windows form, removing its background, maximizing it, adding a label with really large text, and showing the form.

No comments:

Post a Comment