Label aktualisieren

  • Hallo,
    ich will, dass in meiner GUI ein Label alle 5 Sekunden aktualisieren wird.
    Habe es direkt mit AdlibEnable() probiert, aber es funktioniert nicht.
    Das Label soll aber nur dann aktualisiert werden, wenn eine Checkbox gewählt ist.
    Hier mein Script:

    Spoiler anzeigen
    [autoit]

    #include <ButtonConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Test", 211, 128, 519, 263)
    $Input1 = GUICtrlCreateInput("Test", 8, 8, 121, 21)
    $Label1 = GUICtrlCreateLabel("Label1", 12, 64, 100, 17)
    $Label2 = GUICtrlCreateLabel("Label2", 12, 96, 100, 17)
    $Label3 = GUICtrlCreateLabel("Label2", 100, 96, 100, 17)
    $Checkbox1 = GUICtrlCreateCheckbox("Label 1 alle 5 Sekunden aktualisieren", 8, 36, 201, 17)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    EndSwitch
    If GUICtrlRead($Label2) <> GUICtrlRead($Input1) Then GUICtrlSetData($Label2, GUICtrlRead($Input1))
    If GUICtrlRead($Label3) <> GUICtrlRead($Input1) Then GUICtrlSetData($Label3, GUICtrlRead($Input1))
    If BitAND(GUICtrlRead($Checkbox1), $GUI_CHECKED) = $GUI_CHECKED Then
    AdlibEnable("_test", 5000)
    EndIf
    WEnd
    Func _test()
    If GUICtrlRead($Label1) <> GUICtrlRead($Input1) Then GUICtrlSetData($Label1, GUICtrlRead($Input1))
    EndFunc

    [/autoit]

    Einmal editiert, zuletzt von Slyfex (15. November 2009 um 14:10)

  • Kleiner Denkfehler ;) Du musst das AdlibEnable nur aktivieren / deaktivieren, wenn die Checkbox gedrückt wird und nicht andauernd.

    Spoiler anzeigen
    [autoit]

    #include <ButtonConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Test", 211, 128, 519, 263)
    $Input1 = GUICtrlCreateInput("Test", 8, 8, 121, 21)
    $Label1 = GUICtrlCreateLabel("Label1", 12, 64, 100, 17)
    $Label2 = GUICtrlCreateLabel("Label2", 12, 96, 100, 17)
    $Label3 = GUICtrlCreateLabel("Label2", 100, 96, 100, 17)
    $Checkbox1 = GUICtrlCreateCheckbox("Label 1 alle 5 Sekunden aktualisieren", 8, 36, 201, 17)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

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

    $iUpdateTimer = TimerInit()
    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Checkbox1
    Switch BitAND(GUICtrlRead($Checkbox1), $GUI_CHECKED) = $GUI_CHECKED
    Case True
    _Update()
    AdlibEnable("_Update", 5000)
    Case False
    AdlibDisable()
    EndSwitch
    EndSwitch
    If TimerDiff($iUpdateTimer) > 100 Then
    $iUpdateTimer = TimerInit()
    If GUICtrlRead($Label2) <> GUICtrlRead($Input1) Then GUICtrlSetData($Label2, GUICtrlRead($Input1))
    If GUICtrlRead($Label3) <> GUICtrlRead($Input1) Then GUICtrlSetData($Label3, GUICtrlRead($Input1))
    EndIf
    WEnd

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

    Func _Update()
    If GUICtrlRead($Label1) <> GUICtrlRead($Input1) Then GUICtrlSetData($Label1, GUICtrlRead($Input1))
    EndFunc

    [/autoit]

    //Edit: POST 3000 :thumbup:

    2 Mal editiert, zuletzt von progandy (15. November 2009 um 14:40)

  • oder so

    Spoiler anzeigen
    [autoit]

    #include <ButtonConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Test", 211, 128, 519, 263)
    $Input1 = GUICtrlCreateInput("Test", 8, 8, 121, 21)
    $Label1 = GUICtrlCreateLabel("Label1", 12, 64, 100, 17)
    $Label2 = GUICtrlCreateLabel("Label2", 12, 96, 100, 17)
    $Label3 = GUICtrlCreateLabel("Label2", 100, 96, 100, 17)
    $Checkbox1 = GUICtrlCreateCheckbox("Label 1 alle 5 Sekunden aktualisieren", 8, 36, 201, 17)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

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

    AdlibEnable("_test", 5000)

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    EndSwitch
    If GUICtrlRead($Label2) <> GUICtrlRead($Input1) Then GUICtrlSetData($Label2, GUICtrlRead($Input1))
    If GUICtrlRead($Label3) <> GUICtrlRead($Input1) Then GUICtrlSetData($Label3, GUICtrlRead($Input1))
    WEnd

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

    Func _test()
    If BitAND(GUICtrlRead($Checkbox1), $GUI_CHECKED) = $GUI_CHECKED Then ;nur wenn box checked...
    adlibdisable() ;refresh wieder auf 5 Sekunden setzen
    If GUICtrlRead($Label1) <> GUICtrlRead($Input1) Then GUICtrlSetData($Label1, GUICtrlRead($Input1))
    AdlibEnable("_test", 5000); erst wieder nach 5 sekunden testen
    EndIf
    EndFunc ;==>_test

    [/autoit]