• EnglishSpanishGermanFrenchPolishChinese (Traditional)


EnglishSpanishGermanFrenchPolishChinese (Traditional)

Operating systems, scripting, PowerShell and security

Operating systems, software development, scripting, PowerShell tips, network and security

Menú principal
  • Categorías
  • Cursos
  • Libro de PowerShell
  • Lo mejor
  • Lo último
  • Proyectos
  • Contactar
Ir al contenido

Crear formulario dentro de otro formulario mediante una función con PowerShell

PowerShell
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()

Publicado el día 3 de febrero de 2021

CATEGORÍAS

PowerShell

ETIQUETAS

AutoSize, Drawing, Function, Jesús Niño, Jesús Niño Camazón, New-Object, showdialog, size, System.Drawing, System.Windows.Forms.Form, System.Windows.Forms.Label, Windows, Windows.Forms.Form, Write-Host

MÁS

  • Buscar el nombre de una clase de un formulario en PowerShell con Microsoft Spy++
  • Buscar el nombre de una clase de un formulario en PowerShell con Microsoft Spy++ y escribir un mensaje en una caja de texto desde PowerShell
  • Convertir un script de PowerShell en un ejecutable de Windows (convertir un formulario en PowerShell)
  • Crear una aplicación mediante en PowerShell que incremente y disminuya la frecuencia de sonido
  • Ejercicios de PowerShell: realizar operaciones en un equipo remoto
  • Escribir y un mensaje en una caja de texto y hacer click en un botón de un formulario de PowerShell de forma automática utilizando SendMessage y FindWindowEx de user32.dll