Jump to content

Recommended Posts

Posted

How to Hover over 2 labels without blinking when changing color of label setbkcolor with disabled state. I tried 1 label not blinking, but when trying 2 labels it blinks. I am creating 1 button with 2 labels. 1 is the name 2 is the comment

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>


Global $hGUI, $fOver = False, $LbsetOver

$hGUI = GUICreate("Test Hover", 500, 500)

$LbsetOver = GUICtrlCreateLabel("", 8, 8, 84, 59)
GUICtrlSetBkColor($LbsetOver, 0x000000)

GUICtrlSetState($LbsetOver, $GUI_DISABLE)
$LbOver = GUICtrlCreateLabel("Press Me!", 10, 10, 80, 30, $SS_CENTER + $SS_CENTERIMAGE)
GUICtrlSetBkColor(-1, 0xFFF805)
$LbOverPlus = GUICtrlCreateLabel("Plus", 10, 40, 80, 25, $SS_CENTER + $SS_CENTERIMAGE)
GUICtrlSetBkColor(-1, 0xFFF805)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
    _GUICtrlHover($hGUI, $LbOver)
    _GUICtrlHover($hGUI, $LbOverPlus)

WEnd

Func _GUICtrlHover($hwmdover, $ctrlover)
 $aCInfo = GUIGetCursorInfo($hwmdover)
    If $aCInfo[4] = $ctrlover Then
        If $fOver = False Then
            GUICtrlSetBkColor($LbsetOver, 0xFFFFFF)
            $fOver = True
        EndIf
    Else
        If $fOver = True Then
            GUICtrlSetBkColor($LbsetOver, 0x000000)
            $fOver = False
        EndIf
    EndIf
EndFunc

 

  • Moderators
Posted

Loc,

Try this:

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>

Global $hGUI, $fOver = False, $LbsetOver

$hGUI = GUICreate("Test Hover", 500, 500)

$LbsetOver = GUICtrlCreateLabel("", 8, 8, 84, 59)
GUICtrlSetBkColor($LbsetOver, 0x000000)
GUICtrlSetState($LbsetOver, $GUI_DISABLE)

$LbOver = GUICtrlCreateLabel("Press Me!", 10, 10, 80, 30, $SS_CENTER + $SS_CENTERIMAGE)
GUICtrlSetBkColor(-1, 0xFFF805)
$LbOverPlus = GUICtrlCreateLabel("Plus", 10, 40, 80, 25, $SS_CENTER + $SS_CENTERIMAGE)
GUICtrlSetBkColor(-1, 0xFFF805)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
    _GUICtrlHover($hGUI, $LbOver, $LbOverPlus)

WEnd

Func _GUICtrlHover($hwmdover, $ctrl1, $ctrl2)

 $aCInfo = GUIGetCursorInfo($hwmdover)
    If $aCInfo[4] = $ctrl1 Or $aCInfo[4] = $ctrl2 Then
        ; Over labels
        If $fOver = False Then
            GUICtrlSetBkColor($LbsetOver, 0xFFFFFF)
            $fOver = True
        EndIf
    Else
        ; Not over labels
        If $fOver = True Then
            GUICtrlSetBkColor($LbsetOver, 0x000000)
            $fOver = False
        EndIf
    EndIf
EndFunc

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted

A little different :

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>

Local $hGUI = GUICreate("Test Hover", 500, 500)

Local $LbsetOver = GUICtrlCreateLabel("", 8, 8, 84, 59)
GUICtrlSetBkColor($LbsetOver, 0x000000)

GUICtrlSetState($LbsetOver, $GUI_DISABLE)
Local $LbOver = GUICtrlCreateLabel("Press Me!", 10, 10, 80, 30, $SS_CENTER + $SS_CENTERIMAGE)
GUICtrlSetBkColor(-1, 0xFFF805)
Local $LbOverPlus = GUICtrlCreateLabel("Plus", 10, 40, 80, 25, $SS_CENTER + $SS_CENTERIMAGE)
GUICtrlSetBkColor(-1, 0xFFF805)

GUISetState()

While 1
  Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
      Exit
  EndSwitch
  _GUICtrlHover($hGUI, $LbOver, $LbOverPlus)
WEnd

Func _GUICtrlHover($hwmdover, $ctrlover, $ctrloverPlus)
  Local Static $sOver
  Local $aCInfo = GUIGetCursorInfo($hwmdover)
  If $aCInfo[4] = $sOver Then Return
  $sOver = $aCInfo[4]
  If $aCInfo[4] = $ctrlover Then
    GUICtrlSetBkColor($LbsetOver, 0xFFFFFF)
  ElseIf $aCInfo[4] = $ctrloverPlus Then
    GUICtrlSetBkColor($LbsetOver, 0x000000)
  EndIf
EndFunc   ;==>_GUICtrlHover

 

Posted

Thanks for the help. I'm not at the computer right now. $LbOver and $LbOverPlus it can contain [100] and $Lbsetover[100] So you can use For $i = 1 to 99 $ainfo = GUIGetCursorInfo() If $ainfo[4] = $LbOver[$i] Then Guictrlsetbkcolor($Lbsetover[$i]) ElseIf $ainfo[4] = $LbOverPlus[$i] Then Guictrlsetbkcolor($Lbsetover[$i]) Endif next My loop has many functions running and in all functions there is no sleep. When adding _GUICtrlHover() function into the loop, its get the hover function slower than guictrlcreatebutton on hover. Is there any way to improve the speed? I wrote the code according to the incomplete illustration, please forgive me

Posted

I mean create multiple buttons with 2 labels like this. Button generated can be up to 200. Is there a way to fix flickering with multiple generated buttons?

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>

Global $hGUI, $fOver = False, $LbsetOver[2], $LbOver[2], $LbOverPlus[2]

$hGUI = GUICreate("Test Hover", 500, 500)

$LbsetOver[0] = GUICtrlCreateLabel("", 8, 8, 84, 59)
GUICtrlSetBkColor($LbsetOver, 0x000000)
GUICtrlSetState($LbsetOver, $GUI_DISABLE)

$LbOver[0] = GUICtrlCreateLabel("Press Me!", 10, 10, 80, 30, $SS_CENTER + $SS_CENTERIMAGE)
GUICtrlSetBkColor(-1, 0xFFF805)
$LbOverPlus[0] = GUICtrlCreateLabel("Plus", 10, 40, 80, 25, $SS_CENTER + $SS_CENTERIMAGE)
GUICtrlSetBkColor(-1, 0xFFF805)

$LbsetOver[1] = GUICtrlCreateLabel("", 98, 8, 84, 59)
GUICtrlSetBkColor($LbsetOver, 0x000000)
GUICtrlSetState($LbsetOver, $GUI_DISABLE)

$LbOver[1] = GUICtrlCreateLabel("Press Me!", 100, 10, 80, 30, $SS_CENTER + $SS_CENTERIMAGE)
GUICtrlSetBkColor(-1, 0xFFF805)
$LbOverPlus[1] = GUICtrlCreateLabel("Plus", 100, 40, 80, 25, $SS_CENTER + $SS_CENTERIMAGE)
GUICtrlSetBkColor(-1, 0xFFF805)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
    For $i = 0 To 1
    _GUICtrlHover($hGUI, $LbOver[$i], $LbOverPlus[$i], $LbsetOver[$i])
    Next

WEnd

Func _GUICtrlHover($hwmdover, $ctrl1, $ctrl2, $ctrlsetbkcolor)

 $aCInfo = GUIGetCursorInfo($hwmdover)
    If $aCInfo[4] = $ctrl1 Or $aCInfo[4] = $ctrl2 Then
        ; Over labels
        If $fOver = False Then
            GUICtrlSetBkColor($ctrlsetbkcolor, 0xFFFFFF)
            $fOver = True
        EndIf
    Else
        ; Not over labels
        If $fOver = True Then
            GUICtrlSetBkColor($ctrlsetbkcolor, 0x000000)
            $fOver = False
        EndIf
    EndIf
EndFunc

 

Posted (edited)

Here how I would do it :

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>

Global $hGUI, $LbsetOver[2], $LbOver[2], $LbOverPlus[2]

$hGUI = GUICreate("Test Hover", 500, 500)

$LbsetOver[0] = GUICtrlCreateLabel("", 8, 8, 84, 59)
GUICtrlSetBkColor(-1, 0x000000)
GUICtrlSetState(-1, $GUI_DISABLE)

$LbOver[0] = GUICtrlCreateLabel("Press Me!", 10, 10, 80, 30, $SS_CENTER + $SS_CENTERIMAGE)
GUICtrlSetBkColor(-1, 0xFFF805)
$LbOverPlus[0] = GUICtrlCreateLabel("Plus", 10, 40, 80, 25, $SS_CENTER + $SS_CENTERIMAGE)
GUICtrlSetBkColor(-1, 0xFFF805)

$LbsetOver[1] = GUICtrlCreateLabel("", 98, 8, 84, 59)
GUICtrlSetBkColor(-1, 0x000000)
GUICtrlSetState(-1, $GUI_DISABLE)

$LbOver[1] = GUICtrlCreateLabel("Press Me!", 100, 10, 80, 30, $SS_CENTER + $SS_CENTERIMAGE)
GUICtrlSetBkColor(-1, 0xFFF805)
$LbOverPlus[1] = GUICtrlCreateLabel("Plus", 100, 40, 80, 25, $SS_CENTER + $SS_CENTERIMAGE)
GUICtrlSetBkColor(-1, 0xFFF805)

GUISetState()

While 1
  Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
      Exit
  EndSwitch
  _GUICtrlHover($hGUI, $LbOver, $LbOverPlus, $LbsetOver)
WEnd

Func _GUICtrlHover($hwmdover, ByRef $LbOver, ByRef $LbOverPlus, ByRef $LbsetOver)
  Local Static $sOver
  Local $aCInfo = GUIGetCursorInfo($hwmdover)
  If $aCInfo[4] = $sOver Then Return
  $sOver = $aCInfo[4]
  For $i = 0 To UBound($LbsetOver) - 1
    If $sOver = $LbOver[$i] Then Return GUICtrlSetBkColor($LbsetOver[$i], 0xFFFFFF)
  Next
  For $i = 0 To UBound($LbsetOver) - 1
    If $sOver = $LbOverPlus[$i] Then Return GUICtrlSetBkColor($LbsetOver[$i], 0x000000)
  Next
EndFunc   ;==>_GUICtrlHover

 

Edited by Nine
Posted

@Nine Looks like it only jumps in the $LbOver and $LbOverPlus variables, but when it goes out, it doesn't change. I mean when hovering on one of the 2 controls, it will change the color of the border, don't move the mouse on the first ctrl, then ctrl 2 will change the color and vice versa @@

Posted

2 Labels = 1 button. When jumping over another button, the old button color returns to the original state.

Posted

DO NOT PM me asking for help.  I have other activities beside answering to your issues.  Anyway, my last attempt here :

Func _GUICtrlHover($hwmdover, ByRef $LbOver, ByRef $LbOverPlus, ByRef $LbsetOver)
  Local Static $sOver, $iPrev = -1
  Local $aCInfo = GUIGetCursorInfo($hwmdover)
  If $aCInfo[4] = $sOver Then Return
  $sOver = $aCInfo[4]
  If $iPrev >= 0 Then GUICtrlSetBkColor($LbsetOver[$iPrev], 0x000000)
  For $i = 0 To UBound($LbsetOver) - 1
    If $sOver = $LbOver[$i] Then
      $iPrev = $i
      Return GUICtrlSetBkColor($LbsetOver[$i], 0xFFFFFF)
    EndIf
  Next
  For $i = 0 To UBound($LbsetOver) - 1
    If $sOver = $LbOverPlus[$i] Then
      If $iPrev >= 0 Then GUICtrlSetBkColor($LbsetOver[$i], 0x000000)
      ExitLoop
    EndIf
  Next
  $iPrev = -1
EndFunc   ;==>_GUICtrlHover

FYI, it is against forum rules to PM for help.  I suggest you read those to refresh your memory...

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