GUICtrlCreateGroup - Nachträglich Elemente (GUICtrlCreateCheckbox) hinzufügen?

  • Moin,

    Ich habe folgendes Beispiel:

    [autoit]

    #include <ButtonConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #Region ### START Koda GUI section ### Form=C:\_AutoIT\AutoIt.de\Form1.kxf
    $Form1 = GUICreate("Form1", 471, 293, 567, 235)
    $Group1 = GUICtrlCreateGroup("Group1", 24, 24, 425, 217)
    $Radio1 = GUICtrlCreateRadio("Radio1", 40, 48, 113, 17)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    $Button1 = GUICtrlCreateButton("Noch eine Radio-Option", 24, 256, 427, 25)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button1
    ; wie noch einen RadioButton hinzufügen?
    EndSwitch
    WEnd

    [/autoit]

    Jetzt will ich, wenn ich den Button1 betätige eine weitere Checkbox der zuvor erstellten Gruppe hinzufügen - geht das? Wenn ja - Wie?

    Hintergrund: Ich habe eine GUI in der ich für einige Elemente zunächst die Größen, Maßstäbe und Anzahl berechnen muss.
    Erst dann weis ich ob ich 1 oder z.B. 8 Checkboxen brauche.

    Da ich das ganze als Funktion in bestehende Skripte einbauen möchte wäre es schlecht wenn ich dazu das ganze jedesmal innerhalb der Fenstererstellung machen würde.
    Ich würde mich lieber nur auf eine vorhandene Gruppe stürzen - damit ist der Berecih eigentlich klar in dem ich die neuen Elemente packe.

    Ich habe versucht die Gruppe zuerst zu löschen und dann wieder neu zu erstellen (GUICtrlCreateGroup, dann in einer Schleife die Checkboxen, dann nochmal GUICtrlCreateGroup als Abschluss),
    aber das klappt nicht - die Koordinaten werden vom Hauptfenster aus genommen, nicht von der Gruppe aus.

    Danke im voraus,

    BLinz

  • So müsste es doch gehen:

    Spoiler anzeigen
    [autoit]

    #include <ButtonConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #Region ### START Koda GUI section ### Form=C:\_AutoIT\AutoIt.de\Form1.kxf
    $Form1 = GUICreate("Form1", 471, 293, 567, 235)
    $Group1 = GUICtrlCreateGroup("Group1", 24, 24, 425, 217)
    $Radio1 = GUICtrlCreateRadio("Radio1", 40, 48, 113, 17)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    $Button1 = GUICtrlCreateButton("Noch eine Radio-Option", 24, 256, 427, 25)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button1
    GUICtrlDelete($Group1)
    GUICtrlDelete($Radio1); wie noch einen RadioButton hinzufügen?
    $Group1 = GUICtrlCreateGroup("Group1", 24, 24, 425, 217)
    $Radio1 = GUICtrlCreateRadio("Radio1", 40, 48, 113, 17)
    $Radio1 = GUICtrlCreateRadio("Radio2", 40, 68, 113, 17)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    EndSwitch
    WEnd

    [/autoit]

    Edit: So hast dus mit nem Array:

    Spoiler anzeigen
    [autoit]

    #include <ButtonConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <Array.au3>
    #Region ### START Koda GUI section ### Form=C:\_AutoIT\AutoIt.de\Form1.kxf

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

    Dim $Radio[10]

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

    $Form1 = GUICreate("Form1", 471, 293, 567, 235)
    $Group1 = GUICtrlCreateGroup("Group1", 24, 24, 425, 217)
    $Radio[0] = GUICtrlCreateRadio("Radio", 40, 48, 113, 17)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    $Button1 = GUICtrlCreateButton("Noch eine Radio-Option", 24, 256, 427, 25)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

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

    $j = 0

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button1
    If $j < 8 Then $j += 1
    GUICtrlDelete($Group1)
    GUICtrlDelete($Radio)
    $Group1 = GUICtrlCreateGroup("Group1", 24, 24, 425, 217)
    For $i = 0 to UBound($j)
    $Radio[$j] = GUICtrlCreateRadio("Radio"&$j, 40, 48+$j*20, 113, 17)
    Next
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    EndSwitch
    WEnd

    [/autoit]
    [autoit]


    Func Ulam($n)
    Return 1
    EndFunc

    [/autoit]


    Rekursion FTW :D

    Einmal editiert, zuletzt von retrokid (30. November 2011 um 21:40)

  • Wie wärs hiermit?

    [autoit]


    #include <ButtonConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <Array.au3>
    #Region ### START Koda GUI section ### Form=C:\_AutoIT\AutoIt.de\Form1.kxf
    Global $RadioMax = 1, $RadioAbstand = 0
    Dim $Radio[10]

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

    $Form1 = GUICreate("Form1", 471, 293, 567, 235)
    $Group1 = GUICtrlCreateGroup("Group1", 24, 24, 425, 217)
    ;$Radio[0] = GUICtrlCreateRadio("Radio", 40, 48, 113, 17)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    $Button1 = GUICtrlCreateButton("Noch eine Radio-Option", 24, 256, 427, 25)
    _DrawRadio($RadioMax)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button1
    If $RadioMax < 8 Then
    $RadioMax += 1
    _DrawRadio($RadioMax)
    EndIf
    EndSwitch
    WEnd

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

    Func _DrawRadio($Anzahl)
    GUICtrlDelete($Group1)
    GUICtrlDelete($Radio)
    Dim $Radio[10]
    $RadioAbstand = 20

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

    For $i = 1 To $Anzahl
    $Radio[$i] = GUICtrlCreateRadio('Radio'&$i,20,20+$RadioAbstand,100,20)
    $RadioAbstand += 20
    Next
    EndFunc

    [/autoit]

    Gruß