möglichst wenig code für möglichst viele checkboxen

  • Guten Morgen,

    bastele gerade mal ein wenig, wolle eine Gui mit sehr vielen checkboxen erstellen.Verdammt mühsame arbeit wenn jede Box einzelnd erstellt werden soll.
    In meinem sammelsorium habe ich dann diesen Code gefunden, nun frage ich mich, geht das nicht noch kürzer ?

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>

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

    Dim $checkbox[75]

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

    $Form1 = GUICreate("Form1", 875, 600, -1, -1)
    For $i = 0 To UBound($checkbox) - 1
    $top = 75 + ($i * 20)
    $left = 25
    If $top > 356 and $left = 25 Then
    $left = $left + 175
    $top = $top - 300
    EndIf
    If $top > 356 and $left = 200 Then
    $left = $left + 175
    $top = $top - 300
    EndIf
    If $top > 356 and $left = 375 Then
    $left = $left + 175
    $top = $top - 300
    EndIf
    If $top > 356 and $left = 550 Then
    $left = $left + 175
    $top = $top - 300
    EndIf
    $checkbox[$i] = GUICtrlCreateCheckbox("checkbox" & $i, $left, $top, 175, 17)
    Next

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

    GUISetState(@SW_SHOW)

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit

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

    EndSwitch
    WEnd

    [/autoit]

    Gruß
    Pre

  • Hmmm,

    Du kannst Dir noch ein Array erstellen mit Bezeichnungen für jede CB und die dann jeweils durch den Zähler ($i) zuweisen lassen.

    Ansonsten hängt das optimale nur noch von der Anordnung ab.
    Wenn die Anordnung Deiner CB's nur ein-dimensional ist, dann kann man noch kürzen.
    Bei zwei-dimensionaler Anordnung ist da nicht mehr viel drin...

    MfG Schnuffel

    "Sarkasmus ist die niedrigste Form des Witzes, aber die höchste Form der Intelligenz."
    Val McDermid

    über mich...

    ich habe meine Erfahrungen hauptsächlich gesammelt in (grobe Übersicht):

    - RibbonBar Automation
    - MySQL Nutzung
    - GUIs in vielerlei Ausprägung
    - Nutzung von Powershell / Batch in AutoIt
    - Windows Automatisierung

    außerhalb von AutoIt:

    - Sprachen: PS, Batch, php, html(5), javascript, (perl eingeschränkt), vbs
    - Powershell (AD, WPF inkl. Multi-Threading, ...)
    - Deployment-Automatisierung ohne SCCM
    - Office-Nutzung mit COM-Object (AutoIt, PowerShell)
    - ActiveDirectory und alles was damit zusammenhängt
    - Hyper-V Clustering (Converged / Hyper Converged)
    - Serverhardware (Konfiguration, Aufbau, Architektur, Betrieb)

    Lieblingsthema:

    günstige Automatisierung von Vorgängen, für die andere Firmen viel Geld nehmen

    more to come ...

    • Offizieller Beitrag

    Es geht kürzer:

    [autoit]

    Local $checkbox[75]

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

    Local $Form1 = GUICreate("Form1", 875, 600, -1, -1)
    Local $top = 75
    Local $left = 25
    For $i = 0 To UBound($checkbox) - 1
    Switch $i
    Case 15, 30, 45, 60
    $left += 175
    $top = 75
    EndSwitch
    $checkbox[$i] = GUICtrlCreateCheckbox("checkbox" & $i, $left, $top, 175, 17)
    $top += 20
    Next

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

    GUISetState(@SW_SHOW)

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

    While True
    Switch GUIGetMsg()
    Case -3
    Exit
    EndSwitch
    WEnd

    [/autoit]
  • Solltest du eine Liste von Checkboxen wollen, ist eine ListView mit Checkbox-Syle eine Überlegung wert ;)

    • Offizieller Beitrag

    Das Skript von BugFix geht noch etwas kürzer:

    Spoiler anzeigen
    [autoit]


    Local $checkbox[75]

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

    Local $Form1 = GUICreate("Form1", 875, 600, -1, -1)
    Local $top = 75
    Local $left = 25
    For $i = 0 To UBound($checkbox) - 1
    $checkbox[$i] = GUICtrlCreateCheckbox("checkbox" & $i, $left + Mod($i, 5) * 175, $top + Int($i / 5) * 20, 175, 17)
    Next

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

    GUISetState(@SW_SHOW)

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

    While True
    Switch GUIGetMsg()
    Case -3
    Exit
    EndSwitch
    WEnd

    [/autoit]
  • nur so aus Gaudi, ohne jemanden auf die Füße treten zu wollen...

    Es geht noch kürzer :D

    [autoit]

    Local $a_cb[75],$Form1=GUICreate("",875,600),$top=75,$left=25
    For $i=0 To 74
    $a_cb[$i]=GUICtrlCreateCheckbox("checkbox"&$i,$left+Mod($i,5)*175,$top+Int($i/5)*20,175,17)
    Next
    GUISetState()
    Do
    Until GUIGetMsg()=-3

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

    MfG Schnuffel

    "Sarkasmus ist die niedrigste Form des Witzes, aber die höchste Form der Intelligenz."
    Val McDermid

    über mich...

    ich habe meine Erfahrungen hauptsächlich gesammelt in (grobe Übersicht):

    - RibbonBar Automation
    - MySQL Nutzung
    - GUIs in vielerlei Ausprägung
    - Nutzung von Powershell / Batch in AutoIt
    - Windows Automatisierung

    außerhalb von AutoIt:

    - Sprachen: PS, Batch, php, html(5), javascript, (perl eingeschränkt), vbs
    - Powershell (AD, WPF inkl. Multi-Threading, ...)
    - Deployment-Automatisierung ohne SCCM
    - Office-Nutzung mit COM-Object (AutoIt, PowerShell)
    - ActiveDirectory und alles was damit zusammenhängt
    - Hyper-V Clustering (Converged / Hyper Converged)
    - Serverhardware (Konfiguration, Aufbau, Architektur, Betrieb)

    Lieblingsthema:

    günstige Automatisierung von Vorgängen, für die andere Firmen viel Geld nehmen

    more to come ...