Jump to content

How to loop through all textboxes in a form


kcvinu
 Share

Recommended Posts

Hi all,

I have a form with 15 textboxes. I need to set all of them disabled when i press a button. So i decided to use a loop. But how can i do it. Any idea ?

Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to comment
Share on other sites

Thank you @Jos. So simple answer. 

Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to comment
Share on other sites

  • Developers

There is a big difference between the question raised here, using your own gui with controls and using the IE functions.
Why did you think they are related so I understand what you mean?

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

Again, this thread is related to an AutoIt3 GUI, not a webpage.
Create your own thread with the question in the appropriate forum.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

You can do something like this.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 595, 375, 192, 124)
$Input1 = GUICtrlCreateInput("Input1", 144, 24, 289, 21)
$Label1 = GUICtrlCreateLabel("Label1", 160, 64, 36, 17)
$Input2 = GUICtrlCreateInput("Input2", 152, 88, 281, 21)
$Button1 = GUICtrlCreateButton("Button1", 208, 136, 129, 17)
$Input3 = GUICtrlCreateInput("Input3", 32, 24, 89, 21)
$Input4 = GUICtrlCreateInput("Input4", 400, 168, 129, 21)
$Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 72, 136, 97, 33)
$Button2 = GUICtrlCreateButton("Button2", 488, 72, 65, 33)
$Input5 = GUICtrlCreateInput("Input5", 176, 184, 193, 21)
$Input6 = GUICtrlCreateInput("Input6", 416, 240, 129, 21)
$Input7 = GUICtrlCreateInput("Input7", 40, 208, 217, 21)
$Input8 = GUICtrlCreateInput("Input8", 96, 256, 193, 21)
$Button3 = GUICtrlCreateButton("Disable Just Inputs", 200, 304, 209, 49)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button3
        For $i=$Input1 to  $Button3
            if _WinAPI_GetClassName(GUICtrlGetHandle($i))="Edit" Then
                GUICtrlSetState($i,$GUI_DISABLE)
            EndIf
        Next

    EndSwitch
WEnd

Saludos

Link to comment
Share on other sites

@Danyfirex , I am confuced. You are looping through what ? just through control IDs ?. Please clarify the for loop.

Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to comment
Share on other sites

Yes I'm looping through all controls ID and check if is a Edit box. starting from first control ID (the first before the GUI)  till last one. this case $button3.

 

Saludos

 

 

Link to comment
Share on other sites

Thanks. That is new knowledge for me to loop through declared control IDs. Then AutoIt considering control IDs as a list or range. Isn't it ?

Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to comment
Share on other sites

  • Developers

Look inside SciTEConfig for the code that set's up the the "Edit Colors" window. I use a For..Next loop to create the 3 columns of CheckBoxes and also a For..Next loop to see which are checked/

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Moderators

kcvinu,

AutoIt ControlIDs are actually the index numbers of the internal array that AutoIt uses to track the native created controls. They are usually in numerical order, but to save space, the first empty index is used - this means that deleting controls will allow the same ControlID to be reused, as you can see here:

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Test", 500, 500)

For $i = 0 To 9
    $cCID = GUICtrlCreateLabel("", 10, 10 + (20 * $i), 200, 20)
    GUICtrlSetData($cCID, $cCID)
Next

$cReuse = GUICtrlCreateButton("Delete/Recreate", 10, 450, 100, 30)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cReuse

            GUICtrlDelete(5)
            $cCID = GUICtrlCreateLabel("", 10, 10 + (20 * $i), 200, 20)
            GUICtrlSetData($cCID, $cCID)
    EndSwitch

WEnd

M23

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

@Melba23 Interesting !. So if you delete a control, it's ID will be allotted to a new control. But why did this example only shows labels with number 3 ?. I expect it should start from zero.

Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to comment
Share on other sites

@Jos , Did you meant these lines ?

For $x = 1 To 17
    $H_Syn_Label[$x] = GUICtrlCreateLabel($Syn_Label[$x], $BaseX + 5, $BaseY + 20 * $x, 150, 20)
    $H_Syn_Bold[$x] = GUICtrlCreateCheckbox("", $BaseX + 170, $BaseY + 20 * $x, 20, 20)
    $H_Syn_Italic[$x] = GUICtrlCreateCheckbox("", $BaseX + 195, $BaseY + 20 * $x, 20, 20)
    $H_Syn_Underline[$x] = GUICtrlCreateCheckbox("", $BaseX + 220, $BaseY + 20 * $x, 20, 20)
    $H_Syn_fColor[$x] = GUICtrlCreateButton("Fore", $BaseX + 245, $BaseY + 20 * $x, 40, 20)
    $H_Syn_bColor_Standard[$x] = GUICtrlCreateCheckbox("", $BaseX + 295, $BaseY + 20 * $x, 20, 20)
    $H_Syn_bColor[$x] = GUICtrlCreateButton("Back", $BaseX + 320, $BaseY + 20 * $x, 40, 20)
Next

And these are the lines in which you checked for the control state

; Check if one of the checkboxes is clicked
    For $x = 1 To 17
        If $Msg = $H_Syn_bColor_Standard[$x] Then
            $Syn_bColor_Default[$x] = GUICtrlRead($H_Syn_bColor_Standard[$x])
            If GUICtrlRead($H_Syn_bColor_Standard[$x]) = $GUI_CHECKED Then
                GUICtrlSetState($H_Syn_bColor[$x], $GUI_DISABLE)
                $Syn_bColor[$x] = $Background_Color
                GUICtrlSetBkColor($H_Syn_Label[$x], $Syn_bColor[$x])
            Else
                GUICtrlSetState($H_Syn_bColor[$x], $GUI_ENABLE)
            EndIf
            $NeedsSave = 1
        EndIf
        If $Msg = $H_Syn_Bold[$x] Then
            $Syn_Bold[$x] = Not $Syn_Bold[$x]
            $NeedsSave = 1
        EndIf
        If $Msg = $H_Syn_Italic[$x] Then
            $Syn_Italic[$x] = Not $Syn_Italic[$x]
            $NeedsSave = 1
        EndIf
        If $Msg = $H_Syn_Underline[$x] Then
            $Syn_Underline[$x] = Not $Syn_Underline[$x]
            $NeedsSave = 1
        EndIf
        If $Msg = $H_Syn_fColor[$x] Then
            $tempcolor = SelectColor($Syn_fColor[$x])
            $Syn_fColor[$x] = $tempcolor
            GUICtrlSetColor($H_Syn_Label[$x], $Syn_fColor[$x])
            $NeedsSave = 1
        EndIf
        If $Msg = $H_Syn_bColor[$x] Then
            $tempcolor = SelectColor($Syn_bColor[$x])
            $Syn_bColor[$x] = $tempcolor
            GUICtrlSetBkColor($H_Syn_Label[$x], $Syn_bColor[$x])
            $NeedsSave = 1
        EndIf
        If $Msg = $H_Syn_Bold[$x] Or $Msg = $H_Syn_Italic[$x] Or $Msg = $H_Syn_Underline[$x] _
                Or $Msg = $H_Syn_fColor[$x] Or $Msg = $H_Syn_bColor[$x] Then
            GUICtrlSetFont($H_Syn_Label[$x], $SYN_Font_Size, 400 + $Syn_Bold[$x] * 200, $Syn_Italic[$x] * 2 + $Syn_Underline[$x] * 4, $SYN_Font_Type)
            $NeedsSave = 1
        EndIf
    Next

 

Edited by kcvinu
Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to comment
Share on other sites

  • Moderators

kcvinu,

why did this example only shows labels with number 3 ?.

The first ControlID returned has always been 3 since I started using AutoIt - you will have to ask Jon why, but I imagine that the earlier elements are used for other things that AutoIt needs to track.

M23

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

@Melba23 Oh. I deleted label number 2 for a test. But nothing happened and label number 14 created. 

Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to comment
Share on other sites

  • Moderators

kcvinu,

As I explained above, the control ControlIDs start from 3, so using a lower value in a ControlID parameter will not affect any existing control. Thus in this case nothing is deleted and the next created control will follow on from the earlier sequence.

M23

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

Melba23,

But the earlier sequence was ended at 12. So, new control should be created as 13. But it indicates 14. 

Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to comment
Share on other sites

kcvinu,

The first ControlID returned has always been 3 since I started using AutoIt - you will have to ask Jon why, but I imagine that the earlier elements are used for other things that AutoIt needs to track.

M23

always is 3 because autoit create two hidden controls internally. maybe internally use a counter for HMENU parameter of CreateWindowEx.

 

Saludos

 


 

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

×
×
  • Create New...