/\/\o\/\/ PowerShelled

This blog has moved to http://ThePowerShellGuy.com Greetings /\/\o\/\/
$AtomFeed = ("Atom.xml")
$PreviousItems = (" MSH out-zip Function "," get a Users LastLogontime and Domaincontroller fro... "," Some fun With Monads Add-Member, MP3 files and COM "," MSH snap-in to Translate IADsLargeInteger to Int64 "," Commandline editing with MSH. "," MSH Scroll-host function "," Series about Monad on Computerworld "," Watching FSRM Quota and filescreen events from Monad "," More ACL and MSH on MSH for Fun "," Jelle "," ")

Sunday, January 29, 2006

 


Simple Show-Image function for Monad



This function, will show a Image as background of a Form.

this makes it a small Picture viewer,


the static method fromFile of the .NET system.drawing.image class is used to get the Image from the filename.

The script will set the Image as background of the Form and it will size the form to the Size of the picture, if you pull it wider the picture gets tiled.

Also I Implemented a new trick to fix the focus problem, if you do not set the TopMost property of the Form to $true the form shows "hidden" behind the other forms. I did this in all the form examples for this reason.

Grzegorz Niemirowski, pointed me to a way to set this back again after the form is loaded, by using Add_shown in the NG Bringing form to front

(Oops, only when I did look up the link, I see he did the same thing allready , using a Picturebox.)

hmmm,

Strange I had to pick this as an example, without thinking about it, but I will post anyway, for the work and the picture of my niece ;-)



thanks Grzegorz, www.grzegorz.net

gr /\/\o\/\/

# /\/\o\/\/ 2006
# mow001.blogspot.com

Function Show-image {
  param([string]$fileName)

  $Image = [system.drawing.image]::fromfile($filename)

  $form = new system.windows.forms.form
  $form.BackgroundImage = $image;$form.text = $Filename

  $size = $Image.size;$size.width += 8;$size.Height += 30
  $form.size = $size

  $form.topmost = $true
  $Form.Add_Shown({$form.topmost = $false})
  $form.showdialog()
}



Comments:
Anonymous Anonymous
Generally, when I interact with the .net methods that load a file from disk, i need to provide a full path. Fortunately, we have a cmdlet that helps! This line:
$Image = [system.drawing.image]::fromfile($filename)

can be altered to

$Image = [system.drawing.image]::fromfile((resolve-path $filename))

and then you can just pass the file name
 
Blogger /\/\o\/\/
Thanks for the comment en tip

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?