rc-chuah

Hello-World

May 31st, 2022 (edited)
855
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Hide Console Window
  2. $t = '[DllImport("user32.dll")] public static extern bool ShowWindow(int handle, int state);'
  3. Add-Type -Name Win -Member $t -NameSpace Native
  4. [Native.Win]::ShowWindow(([System.Diagnostics.Process]::GetCurrentProcess() | Get-Process).MainWindowHandle, 0)
  5.  
  6. # Load Required Assemblies
  7. [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
  8. Add-Type -AssemblyName PresentationFramework
  9.  
  10. # Drawing Form And Controls
  11. $Form_HelloWorld = New-Object System.Windows.Forms.Form
  12.     $Form_HelloWorld.Text = "Example"
  13.     $Form_HelloWorld.Size = New-Object System.Drawing.Size(272,160)
  14.     $Form_HelloWorld.FormBorderStyle = "FixedDialog"
  15.     $Form_HelloWorld.TopMost = $true
  16.     $Form_HelloWorld.MaximizeBox = $false
  17.     $Form_HelloWorld.MinimizeBox = $false
  18.     $Form_HelloWorld.ControlBox = $true
  19.     $Form_HelloWorld.StartPosition = "CenterScreen"
  20.     $Form_HelloWorld.Font = "Segoe UI"
  21.  
  22. # Adding A Label To My Form
  23. $label_HelloWorld = New-Object System.Windows.Forms.Label
  24.     $label_HelloWorld.Location = New-Object System.Drawing.Size(8,8)
  25.     $label_HelloWorld.Size = New-Object System.Drawing.Size(240,32)
  26.     $label_HelloWorld.TextAlign = "MiddleCenter"
  27.     $label_HelloWorld.Text = "Hello, World!"
  28.     $Form_HelloWorld.Controls.Add($label_HelloWorld)
  29.  
  30. # Add A Button
  31. $button_ClickMe = New-Object System.Windows.Forms.Button
  32.     $button_ClickMe.Location = New-Object System.Drawing.Size(8,80)
  33.     $button_ClickMe.Size = New-Object System.Drawing.Size(240,32)
  34.     $button_ClickMe.TextAlign = "MiddleCenter"
  35.     $button_ClickMe.Text = "Click Me!"
  36.     $button_ClickMe.Add_Click({
  37.         [System.Windows.MessageBox]::Show('Hello, World', 'Example', 'OK', 'Info')
  38.     })
  39.     $Form_HelloWorld.Controls.Add($button_ClickMe)
  40.  
  41. # Show Form
  42. $Form_HelloWorld.Add_Shown({$Form_HelloWorld.Activate()})
  43. [void] $Form_HelloWorld.ShowDialog()
Add Comment
Please, Sign In to add comment