Saturday 18 September 2010

Get-ColourRGB.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script displays the Windows Color dialog box, then 
  4.     displays the r, g, b values of the colours selected  
  5. .DESCRIPTION 
  6.     This script calls windows.forms to show the color dialog. You then  
  7.     select a colour, and hit OK. The script then displays the values you selected. 
  8. .NOTES 
  9.     File Name  : Get-ColourRGB.ps1 
  10.     Author     : Thomas Lee - tfl@psp.co.uk 
  11.     Requires   : PowerShell Version 2.0 
  12. .LINK 
  13.     This script posted to: 
  14.         http://pshscripts.blogspot.com/2010/09/get-colourrgbps1.html 
  15. #> 
  16.  
  17. # Define worker function 
  18. function Get-ColourRGB { 
  19. param
  20. $R = 0,   # Red value 
  21. $G = 0,   # Green value 
  22. $B = 0    # Blue value 
  23. )   
  24.  
  25. # Show colour dialog, get colour  
  26. $colorDialog = New-Object Windows.Forms.ColorDialog -Property @{ 
  27.                FullOpen = $true 
  28.                Color = [Drawing.Color]::FromArgb($R,$G,$B
  29.                } 
  30.      
  31. if ($colorDialog.ShowDialog() -eq "OK") { 
  32.            $R = $colordialog.color.R 
  33.            $G = $colordialog.color.G 
  34.            $B = $colordialog.color.B 
  35.            $R;$G;$B  
  36.     }  
  37.  
  38. # Call the worker function 
  39. $R1,$G1,$B1 = Get-ColourRGB 128 128 128 
  40.  
  41. # Describe  
  42. " You set:" 
  43. " R to: {0}" -f $R1 
  44. " G to: {0}" -f $G1 
  45. " B to: {0}" -f $B1 

No comments: