go to poshgui.com -> click winForm designer -> drag & drop textbox, button -> change color, text in property -> check click in button event
click code tab -> copy auto generated code paste in editor -> complete btn-click code
winform opens -> enter chrome in textbox -> press get process button
a gridview opens to show all chrome process
<# This form was created using POSHGUI.com a free online gui designer for PowerShell
.NAME
Untitled
#>
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.Application]::EnableVisualStyles()
$Form = New-Object system.Windows.Forms.Form
$Form.ClientSize = New-Object System.Drawing.Point(262,182)
$Form.text = "Form"
$Form.TopMost = $false
$Button1 = New-Object system.Windows.Forms.Button
$Button1.text = "Get Process"
$Button1.width = 93
$Button1.height = 30
$Button1.location = New-Object System.Drawing.Point(80,128)
$Button1.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)
$Button1.ForeColor = [System.Drawing.ColorTranslator]::FromHtml("#ffffff")
$Button1.BackColor = [System.Drawing.ColorTranslator]::FromHtml("#4a90e2")
$Label1 = New-Object system.Windows.Forms.Label
$Label1.text = "Name"
$Label1.AutoSize = $true
$Label1.width = 25
$Label1.height = 10
$Label1.location = New-Object System.Drawing.Point(48,64)
$Label1.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)
$TextBox1 = New-Object system.Windows.Forms.TextBox
$TextBox1.multiline = $false
$TextBox1.width = 100
$TextBox1.height = 20
$TextBox1.location = New-Object System.Drawing.Point(119,62)
$TextBox1.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)
$TextBox1.BackColor = [System.Drawing.ColorTranslator]::FromHtml("#f8e71c")
$Form.controls.AddRange(@($Button1,$Label1,$TextBox1))
$Button1.Add_Click({ btnGetProcess_click })
function btnGetProcess_click {
Get-Process $TextBox1.Text | Out-GridView
}
#Write your logic code here
[void]$Form.ShowDialog()
reference:
No comments:
Post a Comment