/\/\o\/\/ PowerShelled

This blog has moved to http://ThePowerShellGuy.com Greetings /\/\o\/\/
$AtomFeed = ("Atom.xml")
$PreviousItems = (" Monad(MSH) Beta 3 is getting closer "," Monad Beta 3 is Coming soon and I got a MVP award "," Adding a Simple AccesRule to a file ACL in MSH "," Colorized MSH LS replacement. "," MSH GUI Viewer for Dataset Example "," More DataTables and joining them in Monad "," MSH Get-MSDN Function "," Getting and Working With SQL Server data in Monad "," MSH Cluster Watcher script "," Monad NewYears Clock "," ")

Friday, January 06, 2006

 


MSH How can I Determine Which Text has been Selected in an Rich Text Box ?



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.mspx

Only 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 :


# 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()  



Comments:
Blogger Sung Meister
Lol, i think porting all the existing Tech Guy's scripts into MSH would be fun of a project to try out :)
 
Blogger /\/\o\/\/
I see you started with translating the MSH scripts to MSH ;-)

http://monadblog.blogspot.com/2006/01/technet-do-scripters-dream-of-magenta.html

good point see my comment there.

gr /\/\o\/\/
 
Post a Comment



<< Home

Archives

October 2005   November 2005   December 2005   January 2006   February 2006   March 2006   April 2006   May 2006   June 2006   July 2006   August 2006   September 2006   October 2006   November 2006   December 2006  

$Links = ("PowerShell RC1 Docs"," PowerShell RC1 X86"," PowerShell RC1 X64"," Monad GettingStarted guide"," Monad Progamming Guide"," Monad SDK"," Monad videos on Channel 9"," MSH Community Workspace"," scripts.readify.net "," MonadSource"," www.reskit.net"," PowerShell Blog"," Under The Stairs"," computerperformance powershell Home"," proudlyserving"," MSH on wikipedia"," MSHWiki Channel 9"," Keith Hill's Blog"," Precision Computing"," PowerShell for fun"," MSH Memo (Japanese)"," monadblog")

find-blog -about "PowerShell","Monad" | out-Technorati.
find-blog -contains "","" | out-Technorati.
Google
 
Web mow001.blogspot.com

This page is powered by Blogger. Isn't yours?