Autoit en español
Aplicaciones con Autoit - Juan Antonio Villalpando
-- Tutorial de iniciación a Autoit --
Volver al índice del tutorial
____________________________
15.- Elegir. CheckBox. Radio.
elegir.exe
- Se trata de pulsar marcar casilleros cuadrados y redondos para elegir distintas opciones.
- De aquí puedes bajar los dibujos de las frutas.
- IMPORTANTE: copiamos las tres imágenes de las frutas en la misma carpeta donde guardemos la aplicación.
__________________________
- Ejecutamos Koda para crear el formulario.
- Si pulsas Tools / Run Form, verás cómo va quedando.
- Pulsamos en Tools / Generate Form Code... y obtenemos el código de situación de los componentes del Formulario.
- Ese código lo copiamos en el Editor SciTE.
- Código final: Formulario del Koda y algoritmo.
Elegir. |
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Elegir - Juan A. Villalpando", 624, 329, 314, 214)
$Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 56, 32, 193, 25)
$Checkbox2 = GUICtrlCreateCheckbox("Checkbox2", 56, 72, 137, 25)
$Checkbox3 = GUICtrlCreateCheckbox("Checkbox3", 56, 112, 153, 25)
$Radio1 = GUICtrlCreateRadio("Fresa", 304, 24, 161, 25)
$Radio2 = GUICtrlCreateRadio("Limón", 304, 64, 161, 33)
$Radio3 = GUICtrlCreateRadio("Pera", 304, 104, 161, 33)
$Pic1 = GUICtrlCreatePic("", 432, 24, 129, 113)
$Label1 = GUICtrlCreateLabel("Label1", 40, 200, 533, 60)
GUISetState(@SW_SHOW)
; Juan A. Villalpando - KIO4.COM
#EndRegion ### END Koda GUI section ###
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
$mensaje_checkbox = ""
While 1
$msg = GuiGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
ExitLoop
EndSelect
;;;;;;;;;;;;;;;;;;;; CheckBox ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
$mensaje_checkbox = ""
If GUICtrlRead($CheckBox1) = 1 Then
$mensaje_checkbox = $mensaje_checkbox & "Marcado el CheckBox1 "
EndIf
If GUICtrlRead($CheckBox2) = 1 Then
$mensaje_checkbox = $mensaje_checkbox & "Marcado el CheckBox2 "
EndIf
If GUICtrlRead($CheckBox3) = 1 Then
$mensaje_checkbox = $mensaje_checkbox & "Marcado el CheckBox3"
EndIf
GUICtrlSetData($Label1,$mensaje_checkbox)
Sleep(50) ; Evita el parpadeo del Label1 y la imagen.
;;;;;;;;;;;;;;;;;;;; Radio ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
If GUICtrlRead($Radio1) = $GUI_CHECKED Then
GUICtrlSetImage ($Pic1, "fresa.gif")
EndIf
If GUICtrlRead($Radio2) = $GUI_CHECKED Then
GUICtrlSetImage ($Pic1, "limon.gif")
EndIf
If GUICtrlRead($Radio3) = $GUI_CHECKED Then
GUICtrlSetImage ($Pic1, "pera.gif")
EndIf
Wend
Exit
|
- Lo ejecutamos: Tools / Go. [En caso de que ya estuviera funcionando pulsamos "Tools / Stop Executing"]
________________________________________________
- Comentarios.
- Es un código un poco complicado de entender para los que empiezan, ya que no saben en qué lugar poner las líneas.
- El Sleep (50) está puesto para que el texto del Label1 y la imagen del Pic1 no parpadeen demasiado.
- En la construcción del Formulario mediante $WS_EX_COMPOSITED y $WS_EX_TRANSPARENT evita el parpadeo (flicker), esto lo veremos en el tutorial 67 de bluetooth.
$Form1 = GUICreate("BT - Juan A. Villalpando", 386, 273, 368, 166, BitOR($WS_MINIMIZEBOX, $WS_SIZEBOX,$WS_EX_COMPOSITED, $WS_EX_TRANSPARENT))
- La convertimos en autoejecutable mediante Aut2Exe, aqui está: elegir.exe
________________________________________________
- Otro código.
- Vamos a utilizar tres Etiquetas (Label) para ver el estado de los CheckBox.
- Además la consulta del elemento activado se hace mediante Case.
elegir2.exe
Elegir2. |
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Elegir - Juan A. Villalpando", 624, 329, 129, 184)
$Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 56, 32, 193, 25)
$Checkbox2 = GUICtrlCreateCheckbox("Checkbox2", 56, 72, 137, 25)
$Checkbox3 = GUICtrlCreateCheckbox("Checkbox3", 56, 112, 153, 25)
$Radio1 = GUICtrlCreateRadio("Fresa", 304, 24, 65, 25)
$Radio2 = GUICtrlCreateRadio("Limón", 304, 64, 81, 33)
$Radio3 = GUICtrlCreateRadio("Pera", 304, 104, 89, 33)
$Pic1 = GUICtrlCreatePic("", 432, 24, 129, 113)
$Label1 = GUICtrlCreateLabel("Label1", 48, 176, 173, 28)
$Label2 = GUICtrlCreateLabel("Label2", 48, 216, 173, 20)
$Label3 = GUICtrlCreateLabel("Label3", 48, 248, 173, 20)
GUISetState(@SW_SHOW)
; Juan A. Villalpando - KIO4.COM
#EndRegion ### END Koda GUI section ###
While 1
$msg = GuiGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
ExitLoop
Case $msg = $CheckBox1
If GUICtrlRead($CheckBox1) = 1 Then
GUICtrlSetData($Label1, "Marcado CheckBox1")
Else
GUICtrlSetData($Label1, "-")
EndIf
Case $msg = $CheckBox2
If GUICtrlRead($CheckBox2) = 1 Then
GUICtrlSetData($Label2, "Marcado CheckBox2")
Else
GUICtrlSetData($Label2, "-")
EndIf
Case $msg = $CheckBox3
If GUICtrlRead($CheckBox3) = 1 Then
GUICtrlSetData($Label3, "Marcado CheckBox3")
Else
GUICtrlSetData($Label3, "-")
EndIf
Case $msg = $Radio1
GUICtrlSetImage ($Pic1, "fresa.gif")
Case $msg = $Radio2
GUICtrlSetImage ($Pic1, "limon.gif")
Case $msg = $Radio3
GUICtrlSetImage ($Pic1, "pera.gif")
EndSelect
Wend
Exit
|
_________________
- Propuesta.
- Cambia el tiempo del Sleep.
|