Okey, als erstes benötigst du eine GUI, die Radio Buttons und ein Button:
Spoiler anzeigen
#include <GUIConstants.au3>
Opt('GUIOnEventMode', 1)
Opt('GUICloseOnEsc', 0)
$GUI = GUICreate('Beispiel', 200, 200)
$Radio_1 = GUICtrlCreateRadio('Radio 1', 15, 20, 100, 20)
$Radio_2 = GUICtrlCreateRadio('Radio 2', 15, 40, 100, 20)
$Radio_3 = GUICtrlCreateRadio('Radio 3', 15, 80, 100, 20)
$Button_1 = GUICtrlCreateButton('Read Radio', 15, 100, 100, 20)
GUISetOnEvent($GUI_EVENT_CLOSE, '_Exit', $GUI)
GUISetState(@SW_SHOW, $GUI)
While Sleep(1000)
WEnd
Func _Exit()
Exit
EndFunc
Wie man sieht, hat es schon die Eigenschaft dass nur 1 ausgewählt wird. Um dies manuell zu bestimmen, benötigst du eine Gruppe für die Radio Buttons:
Spoiler anzeigen
#include <GUIConstants.au3>
Opt('GUIOnEventMode', 1)
Opt('GUICloseOnEsc', 0)
$GUI = GUICreate('Beispiel', 200, 200)
GUICtrlCreateGroup('Gruppe 1', 5, 5, 120, 70)
$Radio_1 = GUICtrlCreateRadio('Radio 1', 15, 20, 100, 20)
$Radio_2 = GUICtrlCreateRadio('Radio 2', 15, 40, 100, 20)
GUICtrlCreateGroup('', -99, -99, 0, 0) ;~ Dies ist wichtig um die 1te Gruppe abzuschließen.
$Radio_3 = GUICtrlCreateRadio('Radio 3', 15, 80, 100, 20)
$Button_1 = GUICtrlCreateButton('Read Radio', 15, 100, 100, 20)
GUISetOnEvent($GUI_EVENT_CLOSE, '_Exit', $GUI)
GUISetState(@SW_SHOW, $GUI)
While Sleep(1000)
WEnd
Func _Exit()
Exit
EndFunc
Nun wird für den Button [Read Radio] eine Funktion erstellt. Diese soll auslesen welche Radio Buttons ausgewählt sind.
Spoiler anzeigen
#include <GUIConstants.au3>
Opt('GUIOnEventMode', 1)
Opt('GUICloseOnEsc', 0)
$GUI = GUICreate('Beispiel', 200, 200)
GUICtrlCreateGroup('Gruppe 1', 5, 5, 120, 70)
$Radio_1 = GUICtrlCreateRadio('Radio 1', 15, 20, 100, 20)
$Radio_2 = GUICtrlCreateRadio('Radio 2', 15, 40, 100, 20)
GUICtrlCreateGroup('', -99, -99, 0, 0) ;~ Dies ist wichtig um die 1te Gruppe abzuschließen.
$Radio_3 = GUICtrlCreateRadio('Radio 3', 15, 80, 100, 20)
$Button_1 = GUICtrlCreateButton('Read Radio', 15, 100, 100, 20)
GUICtrlSetOnEvent($Button_1, '_ReadRadio')
GUISetOnEvent($GUI_EVENT_CLOSE, '_Exit', $GUI)
GUISetState(@SW_SHOW, $GUI)
While Sleep(1000)
WEnd
Func _Exit()
Exit
EndFunc
Func _ReadRadio()
If BitAND(GUICtrlRead($Radio_1), $GUI_CHECKED) Then ConsoleWrite('+> Radio 1 Checked' & @CRLF)
If BitAND(GUICtrlRead($Radio_2), $GUI_CHECKED) Then ConsoleWrite('+> Radio 2 Checked' & @CRLF)
If BitAND(GUICtrlRead($Radio_3), $GUI_CHECKED) Then ConsoleWrite('+> Radio 3 Checked' & @CRLF)
EndFunc
Weil man den 3. Radio Button nicht wieder auf unchecked setzen kann, brauchen wir dafür auch wieder eine Funktion und eine Variable.
Spoiler anzeigen
#include <GUIConstants.au3>
Opt('GUIOnEventMode', 1)
Opt('GUICloseOnEsc', 0)
$Radio3_IsChecked = False
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]$GUI = GUICreate('Beispiel', 200, 200)
GUICtrlCreateGroup('Gruppe 1', 5, 5, 120, 70)
$Radio_1 = GUICtrlCreateRadio('Radio 1', 15, 20, 100, 20)
$Radio_2 = GUICtrlCreateRadio('Radio 2', 15, 40, 100, 20)
GUICtrlCreateGroup('', -99, -99, 0, 0) ;~ Dies ist wichtig um die 1te Gruppe abzuschließen.
$Radio_3 = GUICtrlCreateRadio('Radio 3', 15, 80, 100, 20)
$Button_1 = GUICtrlCreateButton('Read Radio', 15, 100, 100, 20)
GUICtrlSetOnEvent($Button_1, '_ReadRadio')
GUICtrlSetOnEvent($Radio_3, '_ToggleRadio')
GUISetOnEvent($GUI_EVENT_CLOSE, '_Exit', $GUI)
GUISetState(@SW_SHOW, $GUI)
While Sleep(1000)
WEnd
Func _Exit()
Exit
EndFunc
Func _ReadRadio()
If BitAND(GUICtrlRead($Radio_1), $GUI_CHECKED) Then ConsoleWrite('+> Radio 1 Checked' & @CRLF)
If BitAND(GUICtrlRead($Radio_2), $GUI_CHECKED) Then ConsoleWrite('+> Radio 2 Checked' & @CRLF)
If BitAND(GUICtrlRead($Radio_3), $GUI_CHECKED) Then ConsoleWrite('+> Radio 3 Checked' & @CRLF)
EndFunc
Func _ToggleRadio()
If $Radio3_IsChecked = False Then
$Radio3_IsChecked = True
Else
$Radio3_IsChecked = False
GUICtrlSetState($Radio_3, $GUI_UNCHECKED)
EndIf
EndFunc
Das hier mal als kurzer Crash Kurs. Falls es noch fragen geben sollte, frag ruhig...