gottygolly

Using a handle instead of id to interact with a control.

3 posts in this topic

I wasn't sure how to search for this but I did try and couldn't find anything.

In my script I have a for loop create a bunch of labels and through this I was wanting to be able to click on any label and call the function "_Click" so that I can change the color of the box accordingly.

I originally started using @gui_ctrlid to get the id of the label but I realized that once I started adding more code it would mess with getting the correct id. I thought I could use the macro @gui_ctrlhandle but I'm not sure on how to interact with the control through this (normally I would use the ControlId)

The code below should hopefully help you understand if you are confused.

Func _Click()
   $id = @GUI_CtrlHandle
   GUICtrlSetBkColor($id,$color)
EndFunc

Thanks for any help and if you need additional information please let me know so I can aid you in aiding me.

Share this post


Link to post
Share on other sites



gottygolly,

but I realized that once I started adding more code it would mess with getting the correct id

I do not see why it should - ControlIDs to not vary unless you delete and recreate the associated control. This works just fine:

#include <GUIConstantsEx.au3>

Opt("GUIOnEventMode", 1)

$hGUI = GUICreate("Test", 500, 500)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

For $i = 0 To 9
    GUICtrlCreateLabel("", 10, 10 + (30 * $i), 200, 20)
    GUICtrlSetBkColor(-1, 0xCCFFCC)
    GUICtrlSetOnEvent(-1, "_Click")
Next

GUISetState()

While 1
    Sleep(10)
WEnd



Func _Click()
    $cCID = @GUI_CtrlId

    GUICtrlSetBkColor($cCID, 0xFFCCCC)
EndFunc



Func _Exit()
    Exit
EndFunc

M23

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I realized that the function that I posted I had modified and I modified it to work properly, in my script instead of having this:

Func _Click()
   $id = @GUI_CtrlId

   GUICtrlSetBkColor($id,$color)
EndFunc

I had this:

Func _Click()
   $id = @GUI_CtrlId

   GUICtrlSetBkColor($label[$id],$color)
EndFunc

A simple mistake but thank you for the help melba, I compared your example code to my script and found the error that way.

Appreciate it!

Edited by gottygolly

Share this post


Link to post
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