Я использую эту функцию для вызова всплывающего окна для вставки информации:
function Set-Popup ([String]$Title, [String]$Label) {
###################Load Assembly for creating form & button
[void][System.Reflection.Assembly]::LoadWithPartialName( “System.Windows.Forms”)
[void][System.Reflection.Assembly]::LoadWithPartialName( “Microsoft.VisualBasic”)
#####Define the form size & placement
$form = New-Object “System.Windows.Forms.Form”;
$form.Width = 500;
$form.Height = 150;
$form.Text = $title;
$form.StartPosition = [System.Windows.Forms.FormStartPosition]::CenterScreen;
##############Define text label1
$TextLabel1 = New-Object “System.Windows.Forms.Label”;
$TextLabel1.Left = 25;
$TextLabel1.Top = 15;
$TextLabel1.Width = 200;
$TextLabel1.Text = "$Label";
##############Define error label
$ErrorLabel = New-Object “System.Windows.Forms.Label”;
$ErrorLabel.Left = 25;
$ErrorLabel.Top = 65;
$ErrorLabel.Width = 450;
############Define text box1 for input
$TextBox1 = New-Object “System.Windows.Forms.TextBox”;
$TextBox1.Left = 250;
$TextBox1.Top = 10;
$TextBox1.width = 200;
#############define Confirm button
$ConfirmButton = New-Object “System.Windows.Forms.Button”;
$ConfirmButton.Left = 360;
$ConfirmButton.Top = 85;
$ConfirmButton.Width = 100;
$ConfirmButton.Text = “Confirm”;
#############define Cancel button
$CancelButton = New-Object “System.Windows.Forms.Button”;
$CancelButton.Left = 250;
$CancelButton.Top = 85;
$CancelButton.Width = 100;
$CancelButton.Text = “Cancel”;
############# This is when you have to close the form after getting values
$ConfirmBFunc = [System.EventHandler]{
$TextBox1.Text;
$form.Close();
};
$ConfirmButton.Add_Click($ConfirmBFunc);
#############Add controls to all the above objects defined
$form.Controls.Add($ConfirmButton);
$form.Controls.Add($TextLabel1);
$form.Controls.Add($ErrorLabel);
$form.Controls.Add($TextBox1);
$form.ShowDialog();
#################return values
return $TextBox1.Text
}
Это прекрасно работает, как я и ожидал, но когда он завершает работу и использует командлет return, он возвращает «Отмена», и после этого информация, которую я вставил в текстовое поле.
Убей меня, но я действительно не понимаю, что возвращает строку отмены.
![Here I inserted CompTest in the Text Box](https://i.stack.imgur.com/mtdt5.png)
В чем может быть проблема?