Jump to content

Recommended Posts

Posted

Hi

Clicking on Button working But Clicking on label not working

#include <GUIConstants.au3>
#include <Misc.au3>


    $Blue = "0x0000FF"
    $Red = "0xFF0000"
    $FNT = "Comic Sans Ms"

GUICreate ("Test")

$idButton = GUICtrlCreateButton("Change", 210, 170, 85, 25)

    If RegRead("HKEY_CURRENT_USER\Software","Dz") = "0" Then
        $idLabel = GUICtrlCreateLabel ("Label", 122, 74, 100, 18)
        GUICtrlSetColor($idLabel, $Red)
        GUICtrlSetFont(-1, 12, $FW_NORMAL, $GUI_FONTITALIC,$FNT)
    Else
        $idLabel = GUICtrlCreateLabel ("Label", 122, 74, 100, 18)
        GUICtrlSetColor($idLabel, $Blue)
        GUICtrlSetFont(-1, 12, $FW_NORMAL, $GUI_FONTITALIC,$FNT)
        RegWrite("HKEY_CURRENT_USER\Software","Dz","REG_SZ","1")
    EndIf

GUISetState ()
While 1
  Switch GUIGetMsg()

    Case $GUI_EVENT_CLOSE
      ExitLoop

      Case $idButton , $idLabel

        If RegRead("HKEY_CURRENT_USER\Software","Dz") = 1 Then
            $idLabel = GUICtrlCreateLabel ("Label", 122, 74, 100, 18)
            GUICtrlSetColor($idLabel, $Red)
            GUICtrlSetFont(-1, 12, $FW_NORMAL, $GUI_FONTITALIC,$FNT)
            RegWrite("HKEY_CURRENT_USER\Software","Dz","REG_SZ","0")
        Else
            $idLabel = GUICtrlCreateLabel ("Label", 122, 74, 100, 18)
            GUICtrlSetColor($idLabel, $Blue)
            GUICtrlSetFont(-1, 12, $FW_NORMAL, $GUI_FONTITALIC,$FNT)
            RegWrite("HKEY_CURRENT_USER\Software","Dz","REG_SZ","1")
        EndIf

    EndSwitch
Wend

 

Posted

I think you need to set the label style to $SS_RIGHT.

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted (edited)

This is working fine:

- regread/regwrite changed to read/set global variable

- removed unnecessary GUICtrlCreateLabel() from main loop

- some minor fixes/optimizations

 

#include <GUIConstants.au3>
#include <Misc.au3>

Global $switch = 1

$Blue = "0x0000FF"
$Red = "0xFF0000"
$FNT = "Comic Sans Ms"

GUICreate ("Test")

$idButton = GUICtrlCreateButton("Change", 210, 170, 85, 25)

    $idLabel = GUICtrlCreateLabel ("Label", 122, 74, 100, 18)
;~     If RegRead("HKEY_CURRENT_USER\Software","Dz") = "0" Then
    If $switch = 0 Then
        $color = $Red
    Else
        $color = $Blue
        $switch = 1
;~         RegWrite("HKEY_CURRENT_USER\Software","Dz","REG_SZ","1")
    EndIf
    GUICtrlSetColor($idLabel, $color)
    GUICtrlSetFont(-1, 12, $FW_NORMAL, $GUI_FONTITALIC,$FNT)

GUISetState ()

While 1
  Switch GUIGetMsg()

    Case $GUI_EVENT_CLOSE
      ExitLoop

      Case $idButton , $idLabel

        If $switch = 1 Then
;~         If RegRead("HKEY_CURRENT_USER\Software","Dz") = 1 Then
;~             $idLabel = GUICtrlCreateLabel ("Label", 122, 74, 100, 18)
            $color = $Red
            $switch = 0
;~             RegWrite("HKEY_CURRENT_USER\Software","Dz","REG_SZ","0")
        Else
;~             $idLabel = GUICtrlCreateLabel ("Label", 122, 74, 100, 18)
            $color = $Blue
            $switch = 1
;~             RegWrite("HKEY_CURRENT_USER\Software","Dz","REG_SZ","1")
        EndIf
        GUICtrlSetColor($idLabel, $color)
;~        GUICtrlSetFont(-1, 12, $FW_NORMAL, $GUI_FONTITALIC,$FNT)

    EndSwitch
Wend

 

Edited by Zedna
Posted
  On 11/3/2019 at 10:16 PM, Zedna said:

This is working fine:

............ 

Expand  
#include <GUIConstants.au3>
#include <Misc.au3>

$Blue = "0x0000FF"
$Red = "0xFF0000"
$FNT = "Comic Sans Ms"

GUICreate ("Test")

$idButton = GUICtrlCreateButton("Change", 210, 170, 85, 25)

    $idLabel = GUICtrlCreateLabel ("Label", 122, 74, 100, 18)

    If RegRead("HKEY_CURRENT_USER\Software","Dz") = "0" Then
        $color = $Red
    Else
        $color = $Blue
        RegWrite("HKEY_CURRENT_USER\Software","Dz","REG_SZ","1")
    EndIf
    GUICtrlSetColor($idLabel, $color)
    GUICtrlSetFont(-1, 12, $FW_NORMAL, $GUI_FONTITALIC,$FNT)

GUISetState ()

While 1
  Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
      ExitLoop
      Case $idButton , $idLabel
        If RegRead("HKEY_CURRENT_USER\Software","Dz") = 1  Then
            $color = $Red
            RegWrite("HKEY_CURRENT_USER\Software","Dz","REG_SZ","0")
        Else
            $color = $Blue
            RegWrite("HKEY_CURRENT_USER\Software","Dz","REG_SZ","1")
        EndIf
        GUICtrlSetColor($idLabel, $color)
    EndSwitch
Wend

Thanks Zenda

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...