Advertisement
BugFix

Sample PS-GUI

Apr 26th, 2017
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. [void][reflection.assembly]::LoadWithPartialName("System.Windows.Forms")
  2.  
  3.  
  4. $mGUI = new-module -ascustomobject {
  5.     function GuiCreate()
  6.     {
  7.         Param (
  8.             [string]$title,
  9.             [int]$x,
  10.             [int]$y,
  11.             [int]$w,
  12.             [int]$h
  13.         );
  14.         $o = new-object Windows.Forms.Form
  15.         $o.Text = $title
  16.         $o.Left = $x
  17.         $o.Top = $y
  18.         $o.Width = $w
  19.         $o.Height = $h
  20.         return ,$o
  21.     };
  22.  
  23.  
  24.     function ButtonCreate()
  25.     {
  26.         Param (
  27.             [string]$text,
  28.             [int]$x,
  29.             [int]$y,
  30.             [int]$w,
  31.             [int]$h,
  32.             [ScriptBlock]$clickFunc
  33.         );
  34.         $o = new-object Windows.Forms.Button
  35.         $o.Text = $text
  36.         $o.Left = $x
  37.         $o.Top = $y
  38.         $o.Width = $w
  39.         $o.Height = $h
  40.         $o.Add_Click($clickFunc)
  41.         return ,$o
  42.     };
  43.  
  44.  
  45.     function CtrlAdd()
  46.     {
  47.         Param (
  48.             [PsObject]$oGui,
  49.             [PsObject]$oCtrl
  50.         );
  51.         $oGui.Controls.Add($oCtrl)
  52.     }
  53. }
  54.  
  55. $gui = $mGUI.GuiCreate('Test', 100, 100, 600, 400)
  56. $btn = $mGUI.ButtonCreate('OK', 100, 100, 50, 25, {$gui.close()})
  57. $mGUI.CtrlAdd($gui, $btn)
  58. $gui.ShowDialog()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement