Jump to content

Creating checkboxes with counting up.


Recommended Posts

Still experimenting with autoit.. dont know how to get the following to work

I have a GUI, where i need to create multiple(like 50) checkboxes under or next to each other.

Until now i have this code:

Global $CheckboxCount = "50"
For $CheckboxCounter = 1 to $CheckboxCount
  GUICtrlCreateCheckbox("TS00" & $CheckboxCounter & "",5,10)
Next

So i need to create multiple checkboxes with the name TS001, TS002, TS003 etc. Well i think this counter does that job.

The following problem is, how to place the checkboxes under eacher other, so the height must count up with 20 for examples, so it makes height 10, 30, 50 etc.

any help would be appreciated :)

Link to comment
Share on other sites

Untested, but it should get you started

; the 3 in %03d is the length of the number including leading zeros you want
; 8 + ($i * 20)
Local $CheckboxCount = 10
For $CheckboxCounter = 1 to $CheckboxCount  
    GUICtrlCreateCheckbox(StringFormat('TS%03d', $CheckboxCounter), 5, 8 + ($CheckboxCounter * 20)) ; 8 is starting offset, 20 is assumed height
Next
Edited by Robjong
Link to comment
Share on other sites

Works great thanks! I understand what you are doing..

But the next thing is.. what is want now is that the checkboxes after 20, form a new row next to the row 1 til 20.. so it will adjust the width automatically for 21 til 30 etc..

Cant figure it out with if then else..

Link to comment
Share on other sites

how about something like this (again untested)

Local $CheckboxCount = 30, $iOffsetLeft = 5, $iOffsetTop = 10
For $CheckboxCounter = 1 to $CheckboxCount
    GUICtrlCreateCheckbox(StringFormat('TS%03d', $CheckboxCounter), $iOffsetLeft, $iOffsetTop) ; 8 is starting offset, 20 is assumed height
    $iOffsetTop += 20
    If IsInt($CheckboxCounter / 10) Then
        $iOffsetLeft += 150 ; this was item 10, 20 30 etc. so we update offset from the left
        $iOffsetTop = 10
    EndIf
Next

Edit: forgot to reset top offset before

Edited by Robjong
Link to comment
Share on other sites

The checkboxes are created well, but now the problem is that i want to read the $GUI_CHECKED from a particular checkbox when i click the function ButtonServersOk. Apparently i cannot use GUICTRLRead with arrays so i cannot do the $GUI_CHECKED check.

Cant get it to work.

Global $CheckboxArray[50]

Func ButtonServers()
Local $CheckboxCount = 50, $iOffsetLeft = 5, $iOffsetTop = 10

$ServersPopup = GUICreate("Servers",270,440)
GUISetIcon("icon.ico")
TraySetIcon("icon.ico")
$btnServersOk = GUICtrlCreateButton("Ok",5,415,90,20)
GUICtrlSetOnEvent($btnServersOk, "ButtonServersOk")
GUISetOnEvent($GUI_EVENT_CLOSE, "ClosePopup")
GUICtrlCreateCheckbox("Alle servers",100,415)
For $CheckboxCounter = 1 to $CheckboxCount
  GUICtrlCreateCheckbox(StringFormat("TS%03d", $CheckboxCounter), $iOffsetLeft, $iOffsetTop)
  $iOffsetTop += 20
  If IsInt($CheckboxCounter / 20) Then
   $iOffsetLeft += 70
   $iOffsetTop = 10
  EndIf
$CheckboxArray[$CheckboxCounter -1] = $CheckboxCounter
Next

GUISetState(@SW_SHOW, $ServersPopup)
EndFunc

Func ButtonServersOk()
  $CheckboxChecked = GUICtrlRead($CheckboxArray[1])
  If $CheckboxChecked = $GUI_CHECKED Then
  MsgBox(0,"", $CheckboxChecked)
  EndIf
EndFunc
Edited by JoshuaLoman
Link to comment
Share on other sites

  • Moderators

JoshuaLoman,

i cannot use GUICTRLRead with arrays

Of course you can - but you need to loop through the elements like this: ;)

#include <GUIConstantsEx.au3>

Opt("GUIOnEventMode", 1)

Global $ServersPopup, $CheckboxCount = 50, $CheckboxArray[$CheckboxCount + 1]

ButtonServers()

While 1
    Sleep(10)
WEnd

Func ButtonServers()

    Local $iOffsetLeft = 5, $iOffsetTop = 10

    $ServersPopup = GUICreate("Servers", 270, 440)
    GUISetOnEvent($GUI_EVENT_CLOSE, "ClosePopup")
    ;GUISetIcon("icon.ico")
    ;TraySetIcon("icon.ico")
    $btnServersOk = GUICtrlCreateButton("Ok", 5, 415, 90, 20)
    GUICtrlSetOnEvent($btnServersOk, "ButtonServersOk")

    GUICtrlCreateCheckbox("Alle servers", 100, 415)
    For $CheckboxCounter = 1 To $CheckboxCount
        GUICtrlCreateCheckbox(StringFormat("TS%03d", $CheckboxCounter), $iOffsetLeft, $iOffsetTop)
        $iOffsetTop += 20
        If IsInt($CheckboxCounter / 20) Then
            $iOffsetLeft += 70
            $iOffsetTop = 10
        EndIf
        $CheckboxArray[$CheckboxCounter - 1] = $CheckboxCounter
    Next

    GUISetState(@SW_SHOW, $ServersPopup)

EndFunc   ;==>ButtonServers

Func ButtonServersOk()
    For $i = 1 To $CheckboxCount
        If GUICtrlRead($CheckboxArray[$i]) = 1 Then
            MsgBox(0, "", GUICtrlRead($CheckboxArray[$i], 1) & " checked")
        EndIf
    Next
EndFunc   ;==>ButtonServersOk

Func ClosePopup()
    GUIDelete($ServersPopup)
    Exit
EndFunc

All clear? :)

M23

P.S. Please post code that actually works if you want help - not everyone is prepared to add the necessary additional lines for it to run. ;)

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...