Data/Advice/Fun/FunWithGUIs.Advice.json

{
  "Title": "Fun with GUIs",
  "Content": [
    "PowerShell doesn't have to all be about Server administration, ops, or automation.",
    "It can also be fun!",
    "\n",
    "We've provided some fun examples below just to give you a taste of what PowerShell can do",
    "\n",
    "GUIs",
    "\n",
    "\tThe below code snippit will make a blue GUI. When you're more experienced you may",
    "\twant to start making GUIs for your scripts. This is just a quick example.",
    "\n",
    "\tCopy the below into PowerShell ISE to create the GUI!",
    "\n",
    "# Import Assemblies ",
    "[void] [System.Reflection.Assembly]::LoadWithPartialName('System.Drawing')",
    "[void] [System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')",
    "\n",
    "\n",
    "# Create a new form object and assign it to the variable GUIExample",
    "$GUIExample = New-Object System.Windows.Forms.Form",
    "\n",
    "# Define the background image and then set the form to be the same height/width as the image",
    "$BackgroundImage = [System.Drawing.Image]",
    "$GUIExample.BackColor = 'Blue'",
    "$GUIExample.Width = 200",
    "$GUIExample.Height = 400",
    "\n",
    "# Make the GUI the topmost window and give it focus (make it the selected window)",
    "$GUIExample.TopMost = $True",
    "$GUIExample.Add_Shown({$GUIExample.Activate()})",
    "\n",
    "# Show the GUI",
    "[void]$GUIExample.ShowDialog()"
  ]
}