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 95 96 97 98 99 |
# Formulario con sus botones (arriba, abajo, caja de texto) #Beep function #Generates simple tones on the speaker #Beep(Freq,Duration) #Beep(Frecuencia,Duración) #Freq: The frequency of the sound, in hertz #Duration: The duration of the sound, in milliseconds # Definición de componentes $form1 = New-Object System.Windows.Forms.Form $DownButton = New-Object System.Windows.Forms.Button $Upbutton = New-Object System.Windows.Forms.Button # Definición de formulario $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 262 $System_Drawing_Size.Width = 284 $form1.ClientSize = $System_Drawing_Size $form1.DataBindings.DefaultDataSourceUpdateMode = 0 $form1.Name = "formulario" $form1.Text = "Beep" # Definición de botón - $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 224 $System_Drawing_Point.Y = 104 $DownButton.Location = $System_Drawing_Point $DownButton.Name = "-" $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 34 $System_Drawing_Size.Width = 48 $DownButton.Size = $System_Drawing_Size $DownButton.TabIndex = 2 $DownButton.Text = "-" $DownButton.UseVisualStyleBackColor = $True $DownButton.add_Click($handler_DownButton_Click) # Añadir botón al formulario $form1.Controls.Add($DownButton) # Definición de botón + $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 224 $System_Drawing_Point.Y = 48 $Upbutton.Location = $System_Drawing_Point $Upbutton.Name = "+" $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 34 $System_Drawing_Size.Width = 48 $Upbutton.Size = $System_Drawing_Size $Upbutton.TabIndex = 1 $Upbutton.Text = "+" $Upbutton.UseVisualStyleBackColor = $True $Upbutton.add_Click($handler_UpButton_Click) # Añadir botón al formulario $form1.Controls.Add($Upbutton) # Definición de caja de texto con valor por defecto $TextBox = New-Object System.Windows.Forms.TextBox $TextBox.Location = New-Object System.Drawing.Size(100,220) $TextBox.Size = New-Object System.Drawing.Size(50,20) $TextBox.Text = 37 # Añadir cada de texto $form1.Controls.Add($TextBox) # Mostrar el formulario $form1.ShowDialog() # Programar qué hacer cuando se pulsa el + o el - $handler_DownButton_Click= { if([Int]$TextBox.Text -in 37..32766) { [System.Console]::Beep([Int]$TextBox.Text,200) $TextBox.Text = ([Int]$TextBox.Text -1) } else { $TextBox.Text = 37 } } $handler_UpButton_Click= { if([Int]$TextBox.Text -in 37..32766) { [System.Console]::Beep([Int]$TextBox.Text,200) $TextBox.Text = ([Int]$TextBox.Text +1) } else { $TextBox.Text = 37 } } |