Variable hält bei Doppelklick

  • Hallo
    Wenn ich im unten angefügten Script den Button "Label da" zweimal anklicke ohne mal "Label weg" gedrückt zu haben wird die Variable irgendwie gehalten und kann nicht mehr gelöscht werden. Hat jemand ne Lösung ? Ich hab keine Idee wieso das so ist. 8|

    Spoiler anzeigen
    [autoit]


    #include <ButtonConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    Local $Lab
    $Form1 = GUICreate("Test", 486 , 330 , 400 , 183 , $WS_MAXIMIZEBOX)
    $OTC = GUICtrlCreateButton("Label da", 40, 50, 145, 33)
    $BTC = GUICtrlCreateButton("Label weg", 280, 50, 153, 33)
    GUISetState(@SW_SHOW)
    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case -3
    Exit
    Case $OTC
    _set()
    Case $BTC
    _del()
    EndSwitch
    WEnd
    Func _del()
    GUICtrlDelete($Lab)
    EndFunc
    Func _set()
    $Lab = GUICtrlCreateLabel("Ich bin das Label" , 40 , 108 , 390 , 140)
    GUICtrlSetFont(-1, 54, 900, 150, "MS Sans Serif")
    GUICtrlSetBkColor(-1, 0xAAFF00)
    EndFunc

    [/autoit]

    Einmal editiert, zuletzt von Dial (13. November 2010 um 10:52)

  • Du erstellst dann 2 Label übereinander; das oberste ist $Lab. Wenn du nun das oberste löschst, bleibt das darunterliegende erhalten --> es hat die Variable nichtmehr und kann daher nicht über diese gelöscht werden.

  • Erklärung siehe Ineluki :P

    so klappts:

    Spoiler anzeigen
    [autoit]

    #include <ButtonConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    Local $Lab
    $Form1 = GUICreate("Test", 486 , 330 , 400 , 183 , $WS_MAXIMIZEBOX)
    $OTC = GUICtrlCreateButton("Label da", 40, 50, 145, 33)
    $BTC = GUICtrlCreateButton("Label weg", 280, 50, 153, 33)
    GUISetState(@SW_SHOW)
    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case -3
    Exit
    Case $OTC
    _set()
    Case $BTC
    _del()
    EndSwitch
    WEnd
    Func _del()
    GUICtrlDelete($Lab)
    EndFunc
    Func _set()
    If GUICtrlRead($Lab) == 0 Then
    $Lab = GUICtrlCreateLabel("Ich bin das Label" , 40 , 108 , 390 , 140)
    GUICtrlSetFont(-1, 54, 900, 150, "MS Sans Serif")
    GUICtrlSetBkColor(-1, 0xAAFF00)
    EndIf
    EndFunc

    [/autoit]
  • und nun ? wie soll ich die "untere" den wieder wegbekommen. Hab ja keinen 'Namen' dessen


    Ahhhh Dank euch & sry wegen Noob Frage :S

  • Geht aber auch einfacher/kürzer, wenn du das Label unsichtbar erstellst und über deine Buttons nur sichtbar oder unsichtbar machst:

    [autoit]


    #include <ButtonConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>

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

    $Form1 = GUICreate("Test", 486 , 330 , 400 , 183 , $WS_MAXIMIZEBOX)
    $OTC = GUICtrlCreateButton("Label da", 40, 50, 145, 33)
    $BTC = GUICtrlCreateButton("Label weg", 280, 50, 153, 33)
    $Lab = GUICtrlCreateLabel("Ich bin das Label" , 40 , 108 , 390 , 140)
    GUICtrlSetFont(-1, 54, 900, 150, "MS Sans Serif")
    GUICtrlSetBkColor(-1, 0xAAFF00)
    GUICtrlSetState($Lab, $GUI_HIDE) ; Label unsichtbar machen

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

    GUISetState(@SW_SHOW)

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case -3
    Exit
    Case $OTC
    GUICtrlSetState($Lab, $GUI_SHOW) ; Label sichtbar machen
    Case $BTC
    GUICtrlSetState($Lab, $GUI_HIDE) ; Label unsichtbar machen
    EndSwitch
    WEnd

    [/autoit]