Quantcast
Channel: Windows PowerShell Forum
Viewing all articles
Browse latest Browse all 2562

how can we take input from powreshell GUI application and execute the code

$
0
0

I am trying to make powershell GUI application. where I can take input as parameter from GUI and execute it and provide output in table form in GUI.

Below is the code. when code is executed it shows the GUI. when user provide input in both boxes the 'Execute' button is not getting enable. Please let me know what i miss here.

[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")

$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = "U_Status"
$objForm.Size = New-Object System.Drawing.Size(1000,900)
$objForm.StartPosition = "CenterScreen"
$objForm.KeyPreview = $True

$objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape")
    {$objForm.Close()}})

$objLabelc = New-Object System.Windows.Forms.Label
$objLabelc.Location = New-Object System.Drawing.Size(10,20)
$objLabelc.Size = New-Object System.Drawing.Size(75,20)
$objLabelc.Text = "C Path"
$objForm.Controls.Add($objLabelc)


$objTextBoxcbox = New-Object System.Windows.Forms.TextBox
$objTextBoxcbox.Location = New-Object System.Drawing.Size(90,20)
$objTextBoxcbox.Size = New-Object System.Drawing.Size(350,600)
$objForm.Controls.Add($objTextBoxcbox)


$objLabelu = New-Object System.Windows.Forms.Label
$objLabelu.Location = New-Object System.Drawing.Size(10,55)
$objLabelu.Size = New-Object System.Drawing.Size(75,20)
$objLabelu.Text = "U Name"
$objForm.Controls.Add($objLabelu)

$objTextBoxu = New-Object System.Windows.Forms.TextBox
$objTextBoxu.Location = New-Object System.Drawing.Size(90,55)
$objTextBoxu.Size = New-Object System.Drawing.Size(350,600)
$objForm.Controls.Add($objTextBoxu)


$executeButton = New-Object System.Windows.Forms.Button
$executeButton.Location = New-Object System.Drawing.Size(15,85)
$executeButton.Size = New-Object System.Drawing.Size(75,23)
$executeButton.Text = "Execute"
$executeButton.Enabled = $False
$executeButton.Add_Click({
$c.text = $objTextBoxcbox.Text
$u.Text = $objTextBoxu.Text

if(($u.Text -ne $null) -and ($c.text -ne $null))
{
    $executeButton.Enabled = $True
 execute the rest of the code and provide output in GUI output
}
})
$objForm.Controls.Add($executeButton)

$cancelButton = New-Object System.Windows.Forms.Button
$cancelButton.Location = New-Object System.Drawing.Size(100,85)
$cancelButton.Size = New-Object System.Drawing.Size(75,23)
$cancelButton.Text = "Cancel"
$cancelButton.Add_Click({$objForm.Close()})
$objForm.Controls.Add($cancelButton)

$objLabelout = New-Object System.Windows.Forms.Label
$objLabelout.Location = New-Object System.Drawing.Size(10,125)
$objLabelout.Size = New-Object System.Drawing.Size(75,20)
$objLabelout.Text = "Output"
$objForm.Controls.Add($objLabelout)

$objOutputBox = New-Object System.Windows.Forms.TextBox
$objOutputBox.Location = New-Object System.Drawing.Size(10,150)
$objOutputBox.Size = New-Object System.Drawing.Size(800,600)
$objOutputBox.Multiline = $True
$objOutputBox.Font = New-Object System.Drawing.Font("Courier New", "8.5")
$objOutputBox.Wordwrap = $True
$objOutputBox.ReadOnly = $True
$objOutputBox.ScrollBars = [System.Windows.Forms.ScrollBars]::Vertical
$objForm.Controls.Add($objOutputBox)


[void] $objForm.ShowDialog()


Thanks,


Viewing all articles
Browse latest Browse all 2562

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>