Что нового

[Элементы GUI] GUICtrlSetState для нескольких $radio

redwert

Новичок
Сообщения
9
Репутация
0
Задача чтоб при установки статуса checked для одного радиобуттона статус checked распространялся еще на несколько. Но GUICtrlSetState работает только для одного $radio

Код:
#include <GUIConstantsEx.au3>

Opt('MustDeclareVars', 1)

Example()

Func Example()
	Local $radio1, $radio2, $radio3, $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)
	$radio3 = GUICtrlCreateRadio("Radio 3", 10, 70, 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
				GUICtrlSetState($radio2, $GUI_CHECKED) 
				GUICtrlSetState($radio3, $GUI_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


Помогите пожалуйста
 

CreatoR

Must AutoIt!
Команда форума
Администратор
Сообщения
8,671
Репутация
2,481
На то они и Radio, чтобы работать как переключатели. Используй Checkbox:

Код:
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>

Opt('MustDeclareVars', 1)

Example()

Func Example()
    Local $radio1, $radio2, $radio3, $msg
    GUICreate("My GUI radio") ; will create a dialog box that when displayed is centered

    $radio1 = GUICtrlCreateCheckbox("Radio 1", 10, 10, 120, 20, BitOr($GUI_SS_DEFAULT_CHECKBOX, $BS_AUTORADIOBUTTON))
    $radio2 = GUICtrlCreateCheckbox("Radio 2", 10, 40, 120, 20, BitOr($GUI_SS_DEFAULT_CHECKBOX, $BS_AUTORADIOBUTTON))
    $radio3 = GUICtrlCreateCheckbox("Radio 3", 10, 70, 120, 20, BitOr($GUI_SS_DEFAULT_CHECKBOX, $BS_AUTORADIOBUTTON))
    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
                GUICtrlSetState($radio2, $GUI_CHECKED) 
                GUICtrlSetState($radio3, $GUI_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
 

aleratorio

Осваивающий
Сообщения
85
Репутация
43
Можно сделать вот так:
Код:
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)

Example()

Func Example()
    Local $radio1, $radio2, $radio3, $msg
    GUICreate("My GUI radio") ; will create a dialog box that when displayed is centered

	$radio1 = GUICtrlCreateRadio("Radio 1", 10, 10, 120, 20, $WS_GROUP)
	$radio2 = GUICtrlCreateRadio("Radio 2", 10, 40, 120, 20, $WS_GROUP)
	$radio3 = GUICtrlCreateRadio("Radio 3", 10, 70, 120, 20, $WS_GROUP)
    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
					GUICtrlSetState($radio2, $GUI_CHECKED)
					GUICtrlSetState($radio3, $GUI_CHECKED)
			Case $msg = $radio2
					GUICtrlSetState($radio1, $GUI_UNCHECKED)
					GUICtrlSetState($radio3, $GUI_UNCHECKED)
                MsgBox(64, 'Info:', 'You clicked on Radio 2 and it is Checked.')
			Case $msg = $radio3
					GUICtrlSetState($radio1, $GUI_UNCHECKED)
					GUICtrlSetState($radio2, $GUI_UNCHECKED)
        EndSelect
    WEnd
EndFunc   ;==>Example
 
Верх