1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
function formulario1() { #Crear un formulario, añadir una etiqueta, un botón y una caja de texto #Funcionalidad para el formulario: #Pulsar la tecla Enter almacena en una variable el contenido de la caja de texto y se muestra #Pulsar la tecla Escape sale del formulario #Formulario $Form = New-Object System.Windows.Forms.Form $Form.Text="Formulario" $Form.Size=New-Object System.Drawing.Size(500,500) $Form.StartPosition="CenterScreen" #Etiqueta $Label=New-Object System.Windows.Forms.Label $Label.Text="Etiqueta de ejemplo" $Label.AutoSize=$True $Label.Location=New-Object System.Drawing.Size(160,160) #Botón $Button=New-Object System.Windows.Forms.Button $Button.Size=New-Object System.Drawing.Size(75,23) $Button.Text="Botón de ejemplo" $Button.Location=New-Object System.Drawing.Size(180,180) #Caja de texto $TextBox = New-Object System.Windows.Forms.TextBox $TextBox.Location = New-Object System.Drawing.Size(100,220) $TextBox.Size = New-Object System.Drawing.Size(260,20) #Funcionalidad para el formulario: #Pulsar la tecla Enter almacena en una variable el contenido de la caja de texto y se muestra #Pulsar la tecla Escape sale del formulario $Form.KeyPreview = $True $Form.Add_KeyDown({if ($_.KeyCode -eq "Enter"){$Var=$TextBox.Text;Write-Host $Var;$Form.Close()}}) $Form.Add_KeyDown({if ($_.KeyCode -eq "Escape"){$Form.Close()}}) #Añadir etiqueta $Form.Controls.Add($Label) #Añadir botón $Form.Controls.Add($Button) #Añadir caja de texto $Form.Controls.Add($TextBox) $Form.ShowDialog() } #Crear un formulario, añadir una etiqueta, un botón y una caja de texto #Funcionalidad para el formulario: #Pulsar la tecla Enter almacena en una variable el contenido de la caja de texto y se muestra #Pulsar la tecla Escape sale del formulario #Formulario $Form = New-Object System.Windows.Forms.Form $Form.Text="Formulario" $Form.Size=New-Object System.Drawing.Size(500,500) $Form.StartPosition="CenterScreen" #Etiqueta $Label=New-Object System.Windows.Forms.Label $Label.Text="Etiqueta de ejemplo" $Label.AutoSize=$True $Label.Location=New-Object System.Drawing.Size(160,160) #Botón $Button=New-Object System.Windows.Forms.Button $Button.Size=New-Object System.Drawing.Size(75,23) $Button.Text="Botón de ejemplo" $Button.Location=New-Object System.Drawing.Size(180,180) #Caja de texto $TextBox = New-Object System.Windows.Forms.TextBox $TextBox.Location = New-Object System.Drawing.Size(100,220) $TextBox.Size = New-Object System.Drawing.Size(260,20) #Funcionalidad para el formulario: #Pulsar la tecla Enter almacena en una variable el contenido de la caja de texto y se muestra #Pulsar la tecla Escape sale del formulario $Form.KeyPreview = $True $Form.Add_KeyDown({if ($_.KeyCode -eq "Enter"){$Var=$TextBox.Text; formulario1; Write-Host $Var;$Form.Close()}}) $Form.Add_KeyDown({if ($_.KeyCode -eq "Escape"){$Form.Close()}}) #Añadir etiqueta $Form.Controls.Add($Label) #Añadir botón $Form.Controls.Add($Button) #Añadir caja de texto $Form.Controls.Add($TextBox) $Form.ShowDialog() |