Jump to content

Clicking Label to Set Off An Event


 Share

Recommended Posts

I'm trying the fillowing to get a labels data to go into an input box. Is this possible to do by clicking on the label? It's not working this way.

$Label2 = GUICtrlCreateLabel("", 0, 40, 109, 17)

GUICtrlSetBkColor(-1, 0xC0C0C0)

GUISetOnEvent(-1, "putToInputForEditing")

Func putToInputForEditing()

$CtrlID = @GUI_CtrlId

Switch $CtrlID

Case $label2

$readLocLabel = GUICtrlRead($label2)

GUICtrlSetData($input1,$readLocLabel)

EndSwitch

EndFunc

Link to comment
Share on other sites

I'm trying the fillowing to get a labels data to go into an input box. Is this possible to do by clicking on the label? It's not working this way.

$Label2 = GUICtrlCreateLabel("", 0, 40, 109, 17)

GUICtrlSetBkColor(-1, 0xC0C0C0)

GUISetOnEvent(-1, "putToInputForEditing")

Func putToInputForEditing()

$CtrlID = @GUI_CtrlId

Switch $CtrlID

Case $label2

$readLocLabel = GUICtrlRead($label2)

GUICtrlSetData($input1,$readLocLabel)

EndSwitch

EndFunc

Yes I think you're right. If you use OnEvent then you do not detect the label being clicked. If you don't use on event then you can detect when it's clicked.

The help file says

"GUISetOnEvent

Defines a user function to be called when a system button is clicked."

so presumably it's limited to buttons, which includes check boxes and radio buttons which are special buttons.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Works for me :)

#include <GUIConstants.au3>

Opt("GUIOnEventMode", 1)

Global $labels[6]

$y = 10

GuiCreate('Test')
For $i = 1 to 5
    $labels[$i] = GUICtrlCreateLabel("Test " & $i, 10, $y, 109, 17)
    GUICtrlSetOnEvent(-1, "putToInputForEditing")
    GUICtrlSetBkColor(-1, 0xC0C0C0)
    $y = $y + 20
Next
$input1 = GUICtrlCreateInput('', 10, $y, 100, 17)
$Button = GUICtrlCreateButton('Send Edit Back',10, $y + 20, 100, 20)
GUICtrlSetOnEvent(-1, "putToInputForEditing")
GUICtrlSetState(-1, $GUI_DISABLE)
GUISetOnEvent($GUI_EVENT_CLOSE, 'Close') 
GUISetState()

While 1
    Sleep(10)
WEnd

Func putToInputForEditing()
    For $x = 1 To 5
        Select
            Case @GUI_CTRLID = $labels[$x]
                $labels[0] = $labels[$x]
                GUICtrlSetData($input1, GUICtrlRead($labels[$x]))
                GUICtrlSetState($Button, $GUI_ENABLE)
        EndSelect
    Next
    Select
        Case @GUI_CTRLID = $Button
            GUICtrlSetData($labels[0], GUICtrlRead($input1))
            GUICtrlSetData($input1, '')
            GUICtrlSetState($Button, $GUI_DISABLE)
            $labels[0] = ''
    EndSelect       
EndFunc

Func Close()
    Exit
EndFunc

Cheers

Edited by smashly
Link to comment
Share on other sites

Works for me :)

Yes, now I see why the first post didn't work. Instead of GuiCtrlSetOnEvent there was GuiSetOnEvent. :">

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
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...