Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #https://docs.microsoft.com/en-us/powershell/scripting/samples/creating-a-custom-input-box?view=powershell-7.2
- #https://stackoverflow.com/questions/30534273/simple-inputbox-function
- ##https://stackoverflow.com/questions/54037292/folderbrowserdialog-bring-to-front
- function Get-Input
- {
- Param ( [Parameter(Mandatory=0)][string]$Message='Message:',
- [Parameter(Mandatory=0)][string]$Title = 'Title'
- )
- [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
- [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
- $form = New-Object System.Windows.Forms.Form
- $form.Text = $Title
- $form.Size = New-Object System.Drawing.Size(300,200)
- $form.StartPosition = 'CenterScreen'
- $okButton = New-Object System.Windows.Forms.Button
- $okButton.Location = New-Object System.Drawing.Point(75,120)
- $okButton.Size = New-Object System.Drawing.Size(75,23)
- $okButton.Text = 'OK'
- $okButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
- $form.AcceptButton = $okButton
- $form.Controls.Add($okButton)
- $cancelButton = New-Object System.Windows.Forms.Button
- $cancelButton.Location = New-Object System.Drawing.Point(150,120)
- $cancelButton.Size = New-Object System.Drawing.Size(75,23)
- $cancelButton.Text = 'Cancel'
- $cancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
- $form.CancelButton = $cancelButton
- $form.Controls.Add($cancelButton)
- $label = New-Object System.Windows.Forms.Label
- $label.Location = New-Object System.Drawing.Point(10,20)
- $label.Size = New-Object System.Drawing.Size(280,20)
- $label.Text = $Message
- $form.Controls.Add($label)
- $textBox = New-Object System.Windows.Forms.TextBox
- $textBox.Location = New-Object System.Drawing.Point(10,40)
- $textBox.Size = New-Object System.Drawing.Size(260,20)
- $form.Controls.Add($textBox)
- $form.Topmost = $true
- $form.Add_Shown({$textBox.Select()})
- $hndl = [System.Windows.Forms.NativeWindow]::new()
- $hndl.AssignHandle([System.Diagnostics.Process]::GetCurrentProcess().MainWindowHandle)
- $result = $form.ShowDialog($hndl)
- if ($result -eq [System.Windows.Forms.DialogResult]::OK)
- {
- return $textBox.Text
- }else{
- return $null
- }
- }
- Clear-Host
- Get-Input 'Message:' 'Title'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement