Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Hide Console Window
- $t = '[DllImport("user32.dll")] public static extern bool ShowWindow(int handle, int state);'
- Add-Type -Name Win -Member $t -NameSpace Native
- [Native.Win]::ShowWindow(([System.Diagnostics.Process]::GetCurrentProcess() | Get-Process).MainWindowHandle, 0)
- # Load Required Assemblies
- [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
- Add-Type -AssemblyName PresentationFramework
- # Drawing Form And Controls
- $Form_HelloWorld = New-Object System.Windows.Forms.Form
- $Form_HelloWorld.Text = "Example"
- $Form_HelloWorld.Size = New-Object System.Drawing.Size(272,160)
- $Form_HelloWorld.FormBorderStyle = "FixedDialog"
- $Form_HelloWorld.TopMost = $true
- $Form_HelloWorld.MaximizeBox = $false
- $Form_HelloWorld.MinimizeBox = $false
- $Form_HelloWorld.ControlBox = $true
- $Form_HelloWorld.StartPosition = "CenterScreen"
- $Form_HelloWorld.Font = "Segoe UI"
- # Adding A Label To My Form
- $label_HelloWorld = New-Object System.Windows.Forms.Label
- $label_HelloWorld.Location = New-Object System.Drawing.Size(8,8)
- $label_HelloWorld.Size = New-Object System.Drawing.Size(240,32)
- $label_HelloWorld.TextAlign = "MiddleCenter"
- $label_HelloWorld.Text = "Hello, World!"
- $Form_HelloWorld.Controls.Add($label_HelloWorld)
- # Add A Button
- $button_ClickMe = New-Object System.Windows.Forms.Button
- $button_ClickMe.Location = New-Object System.Drawing.Size(8,80)
- $button_ClickMe.Size = New-Object System.Drawing.Size(240,32)
- $button_ClickMe.TextAlign = "MiddleCenter"
- $button_ClickMe.Text = "Click Me!"
- $button_ClickMe.Add_Click({
- [System.Windows.MessageBox]::Show('Hello, World', 'Example', 'OK', 'Info')
- })
- $Form_HelloWorld.Controls.Add($button_ClickMe)
- # Show Form
- $Form_HelloWorld.Add_Shown({$Form_HelloWorld.Activate()})
- [void] $Form_HelloWorld.ShowDialog()
Add Comment
Please, Sign In to add comment