Radio-buttons abfragen wie normale buttons?

  • Hai allerseits,

    ich schreibe gerade ein Programm mit dem man ein Charakterblatt für ein bestimmtes Pen&Paper Rollenspiel erstellen kann (ist für mich damit ich meine ganzen NPCs und sonstigen Charas einfacher verwalten kann - ich mag kein Papierchaos :D).

    Im moment sieht es folgendermaßen aus, ich erstelle ein Label, direkt gefolgt von 10 einzelnen Radiobuttons (jeder ne eigene Gruppe):

    LABEL OOOOO OOOOO

    Jetzt möchte ich folgendes erreichen, wenn ich auf einen dieser Radio Buttons klicke, dann sollen alle Buttons die links davon stehen markiert, und alle Buttons die rechts "entmarkiert".


    Spoiler anzeigen
    [autoit]

    veraltet

    [/autoit]

    **Aktuelles Problem steht weiter im Thread**

    Gruß

    Prajoss

    PS: ihr braucht mir keine fertige Lösung hinschreiben (falls es eine gibt) ein paar Befehle sollten reichen, ich grüble selbst gerne :)

    "Never touch a running System!"

    3 Mal editiert, zuletzt von Prajoss (4. März 2009 um 17:13)

  • Hallo Prajoss,

    so wie sich das liest versuchst du so eine Art Slider zu bauen,
    wenn ja warum verwendest du denn keine Slider?

    $Slider1 = GUICtrlCreateSlider(112, 80, 150, 45)

    zudem könntest du mit Events arbeiten mit Assigen und Arrays:

    Spoiler anzeigen
    [autoit]

    Func _BuildGui($FrameX, $FrameY)
    Global $ButtonGui = GUICreate($ProgName & " Buttons", $FrameX, $FrameY, -1, -1, BitOR($WS_POPUP, $WS_CLIPSIBLINGS))
    GUISetFont(8.5,-1,-1,"Arial",$ButtonGui)
    $FrameY -= 15
    Local $InnerFrame = 16
    Local $InnerFrame2 = $InnerFrame / 2
    Local $InnerFrame4 = $InnerFrame / 4
    Local $cols
    Local $Rows
    Local $Buttons = UBound($ButtonSettings)
    Select
    Case $Buttons = 1
    $cols = 1
    $Rows = 1
    Case $Buttons = 2
    $cols = 1
    $Rows = 2
    Case $Buttons = 3
    $cols = 1
    $Rows = 3
    Case IsInt($Buttons / 2)
    $cols = 2
    $Rows = $Buttons / 2
    Case IsInt($Buttons / 3)
    $cols = 3
    $Rows = $Buttons / 3
    Case IsInt(($Buttons + 1) / 3)
    $cols = 3
    $Rows = ($Buttons + 1) / 3
    Case Else
    $cols = 2
    $Rows = ($Buttons + 1) / 2
    EndSelect

    Local $BSizeX = (($FrameX - $InnerFrame) / $cols) - $InnerFrame4
    If $Buttons >= 12 Then
    If $BSizeX > 150 Then
    $cols *= 2
    $Rows /= 2
    $BSizeX = (($FrameX - $InnerFrame) / $cols) - $InnerFrame4
    EndIf
    EndIf
    Local $BSizeY = (($FrameY - $InnerFrame) / $Rows) - $InnerFrame4
    Local $PosX = $InnerFrame2
    Local $PosY = $InnerFrame2
    $h = 0
    While 1
    For $i = 1 To $Rows
    For $j = 1 To $cols
    Assign("Button" & $h, GUICtrlCreateButton($ButtonSettings[$h][0], $PosX, $PosY, $BSizeX, $BSizeY, 0), 2)
    $PosX += $BSizeX + $InnerFrame4
    $h += 1
    If $h = UBound($ButtonSettings) Then ExitLoop
    Next
    $PosX = $InnerFrame2
    $PosY += $BSizeY + $InnerFrame4
    If $h = UBound($ButtonSettings) Then ExitLoop
    Next
    If $h = UBound($ButtonSettings) Then ExitLoop
    WEnd
    GUICtrlCreateLabel($CopyRightLable, $PosX, $PosY)
    GUICtrlSetFont(-1, $InnerFrame2, -1, -1)
    Global $Tastatur = GUICtrlCreateButton("", $FrameX - $InnerFrame2 - 28 ,$FrameY - $InnerFrame2 , 28 , 20, $BS_ICON)
    GUICtrlSetImage($Tastatur, $TExe, 0)
    GUISetState(@SW_SHOW)
    EndFunc ;==>_BuildGui

    [/autoit]
  • Also Switch ist schonmal deutlich schneller als If.

    Spoiler anzeigen
    [autoit]


    Switch GUIGetMsg()

    Case $GUI_EVENT_CLOSE
    Exit
    Case $beenden
    Beenden()
    Case $neu
    $file = Neu()
    Case $oeffnen
    $file = Oeffnen()
    ;~ Funktion: Blatt erstellen()
    ;~ Funktion: Blatt befüllen()
    Case $speichern
    Speichern()
    ;~ Funktion: Blatt abspeichern()
    Case $KK_P[0][0]
    ;~ MsgBox(0, "hallo", "Erfolg")
    ;~ EndIf
    ;...
    EndSwitch

    [/autoit]

    Twitter: @L3viathan2142
    Benutze AutoIt persönlich nicht mehr, da ich keinen Windows-Rechner mehr besitze.

  • Hey,

    danke erstmal.

    Also ich möchte keinen Slider erstellen, das ganze soll so aussehen (wenns mal fertig ist) --> Siehe Dateianhang

    Deswegen möchte ich das mit den Radiobuttons lösen.

    Mein Problem jetzt noch ist, dass ich nich genau abfragen kann wenn ein Radiobutton geklickt wurde..

    Leider geht das bei einem Radiobutton nicht so ganz.
    Ich möchte sobald ich auf einen der vielen Buttons kriege ein Event auslösen und dabei gleichzeitig die Control-ID des buttons in eine Variable speichern, ist dies möglich?

    wenn ja, bitte nur die Befehle posten, keine komplettlösungen ;)

    Danke und Grüße

    Prajoss

    Edit: Hab jetzt GuiCtrlSetOnEvent() entdeckt, leider kann ich bei der Funktion welche ich bestimme keine Parameter mitübergeben... :(
    - ok Suchfunktion hat sogar mal geholfen, werd noch ein wenig dran sitzen

    "Never touch a running System!"

    2 Mal editiert, zuletzt von Prajoss (4. März 2009 um 15:13)

  • Bei Radiobuttons kann -wie der Name schon sagt- immer nur einer angewählt werden^^
    Schaut also schlecht aus bei dir...
    Ich würde es anders lösen, sei es per Bilder, Icons, oder normalen Buttons
    Sicherlich nicht mit Radios

    Padmak

  • Hey,

    das mit dem anwählen ist ja kein Ding, hab jeden in ne eigene Gruppe gepackt und gut ist ;)

    Edit: OK hab grad den Fehler gefunden (das war ein Geistesblitz)

    Gruß

    Prajoss

    PS: Für Labels mit Icons oder sonstiges würde das Problem ebenfalls bestehen, außerdem hatte ich mit Label-Icons noch andere Probleme^^

    "Never touch a running System!"

    2 Mal editiert, zuletzt von Prajoss (4. März 2009 um 17:13)

  • Habs mit den Radiobuttsons hinbekommen, klappt super :)

    Spoiler anzeigen
    [autoit]

    #include <WindowsConstants.au3>
    #include <GUIConstantsEx.au3>
    #Include <GuiTab.au3>
    #include <GuiButton.au3>
    #Include <File.au3>
    #include <ButtonConstants.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Opt("GUIOnEventMode", 1)
    Opt('TrayIconDebug', 1)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Global Const $ws_left = (@DesktopWidth / 3 - 250) / 2
    Global Const $ws_left_2 = ((@DesktopWidth / 3 - 250) / 2) + (@DesktopWidth / 3)
    Global Const $ws_left_3 = ((@DesktopWidth / 3 - 250) / 2) + (@DesktopWidth / 3 * 2)

    [/autoit] [autoit][/autoit] [autoit]

    Global $tabs[10], $t = 0, $p, $t_aktuell
    Global $KK[10], $GE[10], $WS[10], $CH[10], $MP[10], $EB[10], $WA[10], $IN[10], $GS[10]
    Global $KK_P[10][10], $GE_P[10][10], $WS_P[10][10], $CH_P[10][10], $MP_P[10][10], $EB_P[10][10], $WA_P[10][10], $IN_P[10][10] ,$GS_P[10][10]
    Global $Radios[1000][3], $indexi = 0

    [/autoit] [autoit][/autoit] [autoit]

    $sheet = GUICreate("Vampire Charaktere", @Desktopwidth, @Desktopheight * 0.95, 0, 0, BitOr($WS_MINIMIZEBOX, $WS_SYSMENU, $WS_MAXIMIZEBOX, $WS_MAXIMIZE))
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $menue = GUICtrlCreateMenu("&Datei")

    [/autoit] [autoit][/autoit] [autoit]

    $neu = GUICtrlCreateMenuItem("&Neu", $menue)
    GUICtrlSetOnEvent(-1, "Neu")

    [/autoit] [autoit][/autoit] [autoit]

    $oeffnen = GUICtrlCreateMenuItem("&Öffnen", $menue)
    GUICtrlSetOnEvent(-1, "Oeffnen")

    [/autoit] [autoit][/autoit] [autoit]

    $speichern = GUICtrlCreateMenuItem("&Speichern", $menue)
    ;GUICtrlSetOnEvent(-1, "Speichern")

    GUICtrlCreateMenuItem("", $menue)

    [/autoit] [autoit][/autoit] [autoit]

    $beenden = GUICtrlCreateMenuItem("&Beenden", $menue)
    GUICtrlSetOnEvent(-1, "Beenden")

    [/autoit] [autoit][/autoit] [autoit]

    $tab = GUICtrlCreateTab( 2, 2, @Desktopwidth - 4, @DesktopHeight - 4)

    [/autoit] [autoit][/autoit] [autoit]

    If FileExists(@MyDocumentsDir & "\VampChars\") == 0 Then DirCreate(@MyDocumentsDir & "\VampChars\")

    [/autoit] [autoit][/autoit] [autoit]

    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    While True

    [/autoit] [autoit][/autoit] [autoit]

    Sleep(10)

    [/autoit] [autoit][/autoit] [autoit]

    WEnd

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func Neu()

    $temp = Random( 1000, 9999, 1) & ".ini"

    _FileCreate(@MyDocumentsDir & "\VampChars\" & $temp)

    GUICtrlCreateTabItem($temp)

    Blatt_erstellen()

    GUICtrlCreateTabItem("")

    $file = $temp

    EndFunc

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func Oeffnen()

    $file = FileOpenDialog("Charakterblatt öffnen", @MyDocumentsDir & "\VampChars\", "Charakterblatt (*.ini)", 1 + 2)

    Return

    EndFunc

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func Beenden()

    ;~ Funktion: Blatt eventuell speichern()

    Exit

    EndFunc

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func Blatt_erstellen()

    Local $length = 90, $left = ($ws_left + $length), $left_2 = ($ws_left_2 + $length), $left_3 = ($ws_left_3 + $length) + 10
    Local $abstand

    [/autoit] [autoit][/autoit] [autoit]

    $KK[$t] = GUICtrlCreateLabel("Körperkraft", $ws_left, 400, $length, 20)
    GUICtrlSetFont(-1, 10)

    For $p = 0 To 9 Step 1
    $abstand = Abstand_bestimmen($p)
    GUICtrlCreateGroup("", 1800, 0, 0, 0, -1)
    $KK_P[$t][$p] = GUICtrlCreateRadio("", $left + ($abstand) , 400 , 15, 20)
    GUICtrlSetOnEvent(-1, "Radio")
    $Radios[$indexi][0] = $KK_P[$t][$p]
    $Radios[$indexi][1] = $t
    $Radios[$indexi][2] = $p
    $indexi = $indexi + 1
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    Next

    [/autoit] [autoit][/autoit] [autoit]

    $GE[$t] = GUICtrlCreateLabel("Geschick", $ws_left, 425, $length, 20)
    GUICtrlSetFont(-1, 10)

    [/autoit] [autoit][/autoit] [autoit]

    For $p = 0 To 9 Step 1
    $abstand = Abstand_bestimmen($p)
    GUICtrlCreateGroup("", 1800, 0, 0, 0, -1)
    $GE_P[$t][$p] = GUICtrlCreateRadio("", $left + ($abstand) , 425 , 15, 20)
    GUICtrlSetOnEvent(-1, "Radio")
    $Radios[$indexi][0] = $GE_P[$t][$p]
    $Radios[$indexi][1] = $t
    $Radios[$indexi][2] = $p
    $indexi = $indexi + 1
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    Next

    [/autoit] [autoit][/autoit] [autoit]

    $WS[$t] = GUICtrlCreateLabel("Widerstand", $ws_left, 450, $length, 20)
    GUICtrlSetFont(-1, 10)

    [/autoit] [autoit][/autoit] [autoit]

    For $p = 0 To 9 Step 1
    $abstand = Abstand_bestimmen($p)
    GUICtrlCreateGroup("", 1800, 0, 0, 0, -1)
    $WS_P[$t][$p] = GUICtrlCreateRadio("", $left + ($abstand) , 450 , 15, 20)
    GUICtrlSetOnEvent(-1, "Radio")
    $Radios[$indexi][0] = $WS_P[$t][$p]
    $Radios[$indexi][1] = $t
    $Radios[$indexi][2] = $p
    $indexi = $indexi + 1
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    Next

    [/autoit] [autoit][/autoit] [autoit]

    $CH[$t] = GUICtrlCreateLabel("Charisma", $ws_left_2, 400, $length, 20)
    GUICtrlSetFont(-1, 10)

    [/autoit] [autoit][/autoit] [autoit]

    For $p = 0 To 9 Step 1
    $abstand = Abstand_bestimmen($p)
    GUICtrlCreateGroup("", 1800, 0, 0, 0, -1)
    $CH_P[$t][$p] = GUICtrlCreateRadio("", $left_2 + ($abstand) , 400 , 15, 20)
    GUICtrlSetOnEvent(-1, "Radio")
    $Radios[$indexi][0] = $CH_P[$t][$p]
    $Radios[$indexi][1] = $t
    $Radios[$indexi][2] = $p
    $indexi = $indexi + 1
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    Next

    $MP[$t] = GUICtrlCreateLabel("Manipulation", $ws_left_2, 425, $length, 20)
    GUICtrlSetFont(-1, 10)

    [/autoit] [autoit][/autoit] [autoit]

    For $p = 0 To 9 Step 1
    $abstand = Abstand_bestimmen($p)
    GUICtrlCreateGroup("", 1800, 0, 0, 0, -1)
    $MP_P[$t][$p] = GUICtrlCreateRadio("", $left_2 + ($abstand) , 425 , 15, 20)
    GUICtrlSetOnEvent(-1, "Radio")
    $Radios[$indexi][0] = $MP_P[$t][$p]
    $Radios[$indexi][1] = $t
    $Radios[$indexi][2] = $p
    $indexi = $indexi + 1
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    Next

    $EB[$t] = GUICtrlCreateLabel("Ersch.Bild", $ws_left_2, 450, $length, 20)
    GUICtrlSetFont(-1, 10)

    [/autoit] [autoit][/autoit] [autoit]

    For $p = 0 To 9 Step 1
    $abstand = Abstand_bestimmen($p)
    GUICtrlCreateGroup("", 1800, 0, 0, 0, -1)
    $EB_P[$t][$p] = GUICtrlCreateRadio("", $left_2 + ($abstand) , 450 , 15, 20)
    GUICtrlSetOnEvent(-1, "Radio")
    $Radios[$indexi][0] = $EB_P[$t][$p]
    $Radios[$indexi][1] = $t
    $Radios[$indexi][2] = $p
    $indexi = $indexi + 1
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    Next

    $WA[$t] = GUICtrlCreateLabel("Wahrnehmung", $ws_left_3, 400, $length, 20)
    GUICtrlSetFont(-1, 10)

    [/autoit] [autoit][/autoit] [autoit]

    For $p = 0 To 9 Step 1
    $abstand = Abstand_bestimmen($p)
    GUICtrlCreateGroup("", 1800, 0, 0, 0, -1)
    $WA_P[$t][$p] = GUICtrlCreateRadio("", $left_3 + ($abstand) , 400 , 15, 20)
    GUICtrlSetOnEvent(-1, "Radio")
    $Radios[$indexi][0] = $WA_P[$t][$p]
    $Radios[$indexi][1] = $t
    $Radios[$indexi][2] = $p
    $indexi = $indexi + 1
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    Next

    $IN[$t] = GUICtrlCreateLabel("Intelligenz", $ws_left_3, 425, $length, 20)
    GUICtrlSetFont(-1, 10)

    [/autoit] [autoit][/autoit] [autoit]

    For $p = 0 To 9 Step 1
    $abstand = Abstand_bestimmen($p)
    GUICtrlCreateGroup("", 1800, 0, 0, 0, -1)
    $IN_P[$t][$p] = GUICtrlCreateRadio("", $left_3 + ($abstand) , 425 , 15, 20)
    GUICtrlSetOnEvent(-1, "Radio")
    $Radios[$indexi][0] = $IN_P[$t][$p]
    $Radios[$indexi][1] = $t
    $Radios[$indexi][2] = $p
    $indexi = $indexi + 1
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    Next

    $GS[$t] = GUICtrlCreateLabel("Geistesschärfe", $ws_left_3, 450, $length, 20)
    GUICtrlSetFont(-1, 10)

    For $p = 0 To 9 Step 1
    $abstand = Abstand_bestimmen($p)
    GUICtrlCreateGroup("", 1800, 0, 0, 0, -1)
    $GS_P[$t][$p] = GUICtrlCreateRadio("", $left_3 + ($abstand) , 450 , 15, 20)
    GUICtrlSetOnEvent(-1, "Radio")
    $Radios[$indexi][0] = $GS_P[$t][$p]
    $Radios[$indexi][1] = $t
    $Radios[$indexi][2] = $p
    $indexi = $indexi + 1
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    Next

    $t = $t + 1

    EndFunc

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func Abstand_bestimmen($Index)
    If $Index >= 5 Then
    Return $Index * 15 + 5
    Else
    Return $Index * 15
    EndIf
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _Exit()

    Exit

    EndFunc

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func Radio()

    For $i = 0 To ($indexi - 1) Step 1
    If $Radios[$i][0] == @GUI_CtrlId Then
    Radios_check($i, $Radios[$i][2])
    Radios_uncheck($i, $Radios[$i][2])
    Return
    EndIf
    Next

    [/autoit] [autoit][/autoit] [autoit]

    EndFunc

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func Radios_check($Ctrl_ID, $index_2)

    While $index_2 >= 0

    GUICtrlSetState($Radios[$Ctrl_ID][0], $GUI_CHECKED)

    $Ctrl_ID = $Ctrl_ID - 1
    $index_2 = $index_2 - 1
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    EndFunc

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func Radios_uncheck($Ctrl_ID, $index_2)

    While $index_2 + 1 < 10

    GUICtrlSetState($Radios[$Ctrl_ID + 1][0], $GUI_UNCHECKED)

    $Ctrl_ID = $Ctrl_ID + 1
    $index_2 = $index_2 + 1

    WEnd

    EndFunc

    [/autoit]

    hab n bischen gebraucht für den Algorythmus aber es funzt 8)

    Gruß

    Prajoss

    "Never touch a running System!"