This blog has moved to http://ThePowerShellGuy.com
Greetings /\/\o\/\/
As the scripting guys are back, I decided to copy them another time,
I did this HTA script but then ofcourse in Monad :
How Can I Determine Which Text has been Selected in an HTA?
http://www.microsoft.com/technet/scriptcenter/resources/qanda/default.mspxOnly I do it with a Windows Form with a Menu and hosting an Rich Text Box.
It will write the selected text to the MSH console.
The script is a big bigger for the menu, but now it's easy to add for example more usefull items as a save Menu-item, calling the SaveFile of $rtb you almost have made Notepad in MSH (with Wordpad aspirations as it is RTF)
also you can copy text in (formatted) and prefill it from MSH, and set tab's so you can make a rtf reports from MSH.
it looks like this :
if you have seen former UI samples you might notice that I do not dock the RichtextBox, as then it will we partly under the menu, but I do size $rtb and the form then anchor the richtextbox to the Form so it does autosize.
Also you might notice all the string shortcuts to the .NET Enums (for example anchor),
that make creating a form and placing conrols from script very easy.
I did not find out about them at the time, hence the Dock method, but this let's you finetune your form more and place more controls possible.
also note the Scriptblocks used as eventHandlers, you can add complete scripts there, handling the Menu Items.
so you see it's much more powerfull as it looks.
have fun.
gr /\/\o\/\/
Tags : Monad msh# RTBExample.msh
# /\/\o\/\/ 2006
# http://mow001.blogspot.com
#
# Based on :
# How Can I Determine Which Text has been Selected in an HTA?
# http://www.microsoft.com/technet/scriptcenter/resources/qanda/default.mspx
# Build Form
$form = new-object System.Windows.Forms.form
$Form.text = "MSH RTB test"
$form.Size = "800,400"
# Build Menu
$MS = new-object System.Windows.Forms.MenuStrip
$Mi = new-object System.Windows.Forms.ToolStripMenuItem("&File")
$Msi1 = new-object System.Windows.Forms.ToolStripMenuItem("&Selected")
$msi1.add_Click({write-host $rtb.SelectedText})
$Mi.DropDownItems.Add($msi1)
$Msi2 = new-object System.Windows.Forms.ToolStripMenuItem("&Quit")
$msi2.add_Click({$form.close()})
$Mi.DropDownItems.Add($msi2)
$ms.Items.Add($mi)
$form.Controls.Add($ms)
# Add Rich Text Box
$rtb = new-object System.Windows.Forms.RichTextBox
$rtb.Location = "10,30"
$rtb.size = "780,360"
$rtb.Anchor = "top, bottom, left, right"
$form.Controls.Add($rtb)
# show Form
$form.topmost = $true
$form.showdialog()