• 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 (nivel medio)
  • Libro de PowerShell (nivel avanzado)
  • Lo mejor
  • Lo último
  • Proyectos
  • Contactar
Ir al contenido

Ejercicios de PowerShell: crear un interfaz simple que realice la operación de suma, resta y multiplicación

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
$form = [System.Windows.Forms.Form] @{
    Text = 'Mi formulario'
}
$Label1 = [System.Windows.Forms.Label] @{
    Text = "Número 1"
    Location = "40,20"
}
$TextBox1 = [System.Windows.Forms.TextBox] @{
    Text = ""
    Location = "150,20"
}
$Label2 = [System.Windows.Forms.Label] @{
    Text = "Número 2"
    Location = "40,50"
}
$TextBox2 = [System.Windows.Forms.TextBox] @{
    Text = ""
    Location = "150,50"
}
$Button1 = [System.Windows.Forms.Button] @{
    Text = "+"
    Location = "20,100"
}
$Button2 = [System.Windows.Forms.Button] @{
    Text = "-"
    Location = "110,100"
}
$Button3 = [System.Windows.Forms.Button] @{
    Text = "*"
    Location = "200,100"
}
$TextBox3 = [System.Windows.Forms.TextBox] @{
    Text = ""
    Location = "100,150"
}
 
function suma()
{
    $suma = [Int]$TextBox1.text + [Int]$TextBox2.text
    $TextBox3.Text = $suma
}
 
function resta()
{
    $resta = [Int]$TextBox1.text - [Int]$TextBox2.text
    $TextBox3.Text = $resta
}
 
function multi()
{
    $multi = [Int]$TextBox1.text * [Int]$TextBox2.text
    $TextBox3.Text = $multi
}
 
$Button1.add_click({suma})
$Button2.add_click({resta})
$Button3.add_click({multi})
 
$form.Controls.Add($Label1)
$form.Controls.Add($TextBox1)
$form.Controls.Add($Label2)
$form.Controls.Add($TextBox2)
$form.Controls.Add($Button1)
$form.Controls.Add($Button2)
$form.Controls.Add($Button3)
$form.Controls.Add($TextBox3)
$form.ShowDialog()
Publicado el día 18 de marzo de 2021

CATEGORÍAS

PowerShell

ETIQUETAS

Ejercicios de PowerShell, Function, Jesús Niño, Jesús Niño Camazón, showdialog, System.Windows.Forms, System.Windows.Forms.Form, System.Windows.Forms.Label, Windows, Windows.Forms.Form

MÁS

  • Ejercicios de PowerShell: crear un prototipo con formularios en PowerShell (utilizar botones, etiquetas y cajas de texto)
  • Automatizar el funcionamiento de una aplicación que simula un piano (pulsar automáticamente las notas del piano)
  • Proyectos e ideas: automatización
  • Crear un formulario con dos botones (uno de los botones deshabilitado) en PowerShell
  • 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
  • Crear una aplicación mediante en PowerShell que incremente y disminuya la frecuencia de sonido
Jesusninoc utiliza cookies: saber más aquí.