Skip to content

Instantly share code, notes, and snippets.

Created November 29, 2016 19:43
Show Gist options
  • Save anonymous/eb1de4f4affe510e7c5363103592733d to your computer and use it in GitHub Desktop.
Save anonymous/eb1de4f4affe510e7c5363103592733d to your computer and use it in GitHub Desktop.
function button ($title,$mailbx, $WF, $E) {
###################Load Assembly for creating form & button######
[void][System.Reflection.Assembly]::LoadWithPartialName( “System.Windows.Forms”)
[void][System.Reflection.Assembly]::LoadWithPartialName( “System.Drawing”)
[void][System.Reflection.Assembly]::LoadWithPartialName( “Microsoft.VisualBasic”)
#####Define the form size & placement
$form = New-Object “System.Windows.Forms.Form”;
$form.Width = 500;
$form.Height = 300;
$form.Text = $title;
$form.StartPosition = [System.Windows.Forms.FormStartPosition]::CenterScreen;
##############Define text label1
$textLabel1 = New-Object “System.Windows.Forms.Label”;
$textLabel1.Size = New-Object System.Drawing.Size(100,50);
$textLabel1.Left = 15;
$textLabel1.Top = 15;
$textLabel1.Text = $mailbx;
##############Define text label2
$textLabel2 = New-Object “System.Windows.Forms.Label”;
$textLabel2.Size = New-Object System.Drawing.Size(100,50);
$textLabel2.Left = 15;
$textLabel2.Top = 65;
$textLabel2.Text = $WF;
##############Define text label3
$textLabel3 = New-Object “System.Windows.Forms.Label”;
$textLabel3.Size = New-Object System.Drawing.Size(100,50);
$textLabel3.Left = 15;
$textLabel3.Top = 115;
$textLabel3.Text = $E;
############Define text box1 for input
$textBox1 = New-Object “System.Windows.Forms.TextBox”;
$textBox1.Left = 115;
$textBox1.Top = 15;
$textBox1.width = 350;
############Define text box2 for input
$textBox2 = New-Object “System.Windows.Forms.TextBox”;
$textBox2.Left = 115;
$textBox2.Top = 65;
$textBox2.width = 350;
############Define text box3 for input
$textBox3 = New-Object “System.Windows.Forms.TextBox”;
$textBox3.Left = 115;
$textBox3.Top = 115;
$textBox3.width = 350;
###TEST
$checkBox1 = New-Object "System.Windows.Forms.CheckBox";
$checkBox1.Left = 115;
$checkBox1.Top = 150;
$checkBox1.UseVisualStyleBackColor = $True
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 104
$System_Drawing_Size.Height = 24
$checkBox1.Size = $System_Drawing_Size
$checkBox1.TabIndex = 0
$checkBox1.Text = "CheckBox 1"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 27
$System_Drawing_Point.Y = 150
$checkBox1.Location = $System_Drawing_Point
$checkBox1.DataBindings.DefaultDataSourceUpdateMode = 0
$checkBox1.Name = "checkBox1"
$form.Controls.Add($checkBox1)
#############Define default values for the input boxes
$defaultValue = “”
$textBox1.Text = $defaultValue;
$textBox2.Text = $defaultValue;
$textBox3.Text = $defaultValue;
#############define OK button
$button = New-Object “System.Windows.Forms.Button”;
$button.Left = 170;
$button.Top = 120;
$button.Width = 100;
$button.Text = “Ok”;
############# This is when you have to close the form after getting values
$eventHandler = [System.EventHandler]{
$textBox1.Text;
$textBox2.Text;
$textBox3.Text;
$checkBox1.CheckState;
$form.Close();};
$button.Add_Click($eventHandler) ;
#############Add controls to all the above objects defined
$form.Controls.Add($button);
$form.Controls.Add($textLabel1);
$form.Controls.Add($textLabel2);
$form.Controls.Add($textLabel3);
$form.Controls.Add($textBox1);
$form.Controls.Add($textBox2);
$form.Controls.Add($textBox3);
$ret = $form.ShowDialog();
#################return values
return $textBox1.Text, $textBox2.Text, $testBox3.Text, $checkBox1.CheckState
}
$return= button “Enter specifications for Caption Report” “Date (MM/DD/YY):” “File Name:” “Email:”
#Below variables will get the values that had been entered by the user
$date =$return[0]
$return[1]
if ($return[3].Checked){
write-host ya
}
else
{
write-host nah
}
pause
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment