Jump to content

Clicking on label not working


Recommended Posts

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

 

Link to comment
Share on other sites

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

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

7 hours ago, Zedna said:

This is working fine:

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

#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

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...