J'ai une application avec un quarantaine de boutons radio. Aucun problème pour exécuter une action après sélection d'un bouton radio.
Mon problème est que pendant l'exécution du traitement l'utilisateur peut le stopper. Ce qui fait que je désire mettre en rouge l'arrière plan du bouton radio qui est sélectionné (ça je sais faire ). Par contre je ne parviens pas à relire quel bouton radio est cocher en utilisant une variable dynamique pour éviter d'écrire autant de lignes qu'il y a de bouton. (voir fonction _checkChecked).
#include <GUIConstantsEx.au3>
#include <array.au3>
;~ Opt('MustDeclareVars', 1)
Global $radio1, $radio2, $listBtn1
Example()
_checkChecked()
Func Example()
Local $radio1, $radio2, $msg
GUICreate("My GUI radio") ; will create a dialog box that when displayed is centered
$radio1 = GUICtrlCreateRadio("Radio 1", 10, 10, 120, 20)
$radio2 = GUICtrlCreateRadio("Radio 2", 10, 40, 120, 20)
GUICtrlSetState($radio2, $GUI_CHECKED)
GUISetState() ; will display an dialog box with 1 checkbox
; Run the GUI until the dialog is closed
While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
ExitLoop
Case $msg = $radio1 And BitAND(GUICtrlRead($radio1), $GUI_CHECKED) = $GUI_CHECKED
MsgBox(64, 'Info:', 'You clicked the Radio 1 and it is Checked.')
Case $msg = $radio2 And BitAND(GUICtrlRead($radio2), $GUI_CHECKED) = $GUI_CHECKED
MsgBox(64, 'Info:', 'You clicked on Radio 2 and it is Checked.')
EndSelect
WEnd
EndFunc ;==>Example
Func _checkChecked()
Local $listBtn[1]
For $a = 0 To 1
_ArrayAdd($listBtn, "$radio" & $a + 1)
Next
;~ _ArrayDisplay($listBtn)
For $i = 1 To UBound($listBtn) - 1 ; boucle de test de chaque sosu menu
If BitAND(GUICtrlRead($listBtn[$i]), $GUI_CHECKED) = $GUI_CHECKED Then
MsgBox(0, "ok", $listBtn[$i] & " checked")
EndIf
Next
Exit
EndFunc ;==>_checkChecked
Merci pour vos solutions.
Modifié en dernier par softwater le mer. 14 déc. 2011 08:19, modifié 1 fois.
#include <GUIConstantsEx.au3>
#include <array.au3>
Opt('MustDeclareVars', 1)
Global $NbRadio = 2
Global $Radio[$NbRadio]
Example()
_checkChecked()
Func Example()
Local $radio1, $radio2, $msg
GUICreate("My GUI radio") ; will create a dialog box that when displayed is centered
$Radio[0] = GUICtrlCreateRadio("Radio 1", 10, 10, 120, 20)
$Radio[1] = GUICtrlCreateRadio("Radio 2", 10, 40, 120, 20)
GUICtrlSetState($Radio[1], $GUI_CHECKED)
GUISetState() ; will display an dialog box with 1 checkbox
; Run the GUI until the dialog is closed
While 1
$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then ExitLoop
For $i = 0 To $NbRadio - 1
If $msg = $Radio[$i] And BitAND(GUICtrlRead($Radio[$i]), $GUI_CHECKED) = $GUI_CHECKED Then MsgBox(64, 'Info:', 'You clicked the Radio ' & $i + 1 & ' and it is Checked.')
Next
WEnd
EndFunc ;==>Example
Func _checkChecked()
For $i = 0 To $NbRadio - 1 ; boucle de test de chaque sosu menu
If BitAND(GUICtrlRead($Radio[$i]), $GUI_CHECKED) = $GUI_CHECKED Then
MsgBox(0, "ok Radio", $i + 1 & " checked")
EndIf
Next
Exit
EndFunc ;==>_checkChecked