Jump to content

Recommended Posts

Posted

im using guictrlsetbkcolor on a label in a while loop and the label is constantly flickering very fast and I was wondering how can i make the flickering completely stop. the label background color is updating fine but it is flickering. i dont think sleep will work as all it does is pauses the loop...

please help as i dont know what to do

Posted

I used this example:

$GUI = GUICreate("LABEL",200,200,-1,-1)
$LABEL = GUICtrlCreateLabel("TEST",50,50,100,100,0x01)
GUISetState(@SW_SHOW)

While 1
    $MSG = GUIGetMsg()
    If $MSG = -3 Then Exit
    GUICtrlSetBkColor($LABEL,Random(0x000000,0xffffff,1))
    Sleep(500)
WEnd

Sometimes it is flickering, maybe is important dimensions of label.

Posted

im using guictrlsetbkcolor on a label in a while loop and the label is constantly flickering very fast and I was wondering how can i make the flickering completely stop. the label background color is updating fine but it is flickering. i dont think sleep will work as all it does is pauses the loop...

please help as i dont know what to do

Are you changing the colour everytime or is your loop just setting a colour which is possibly already set but you haven't taken that in to concideration so your just setting it again anyway?

Posted (edited)

Are you changing the colour everytime or is your loop just setting a colour which is possibly already set but you haven't taken that in to concideration so your just setting it again anyway?

yeah pretty much

Edited by nowagain
Posted

yeah pretty much

Well don't!

Store the current colour in a $variable, if the new colour is still the same as the old colour stored in teh $Variable then do nothing, if the new colour is different to that stored in the $variable then update the label colour and store the new colour in the $variable

Posted

I had the same problem. Like ChrisL said, instead of checking what the background color is, Just store the color in a variable every time you change it, so you will still have the value on hand.

Maybe this will give you some insight. It's a color picker I wrote a while ago.

#include <GUIConstantsEx.au3>
#Include <Misc.au3>
#include <EditConstants.au3>
Global $nCont = 0, $xColor = 0x000000, $iRunning = False
$hGUI = GUICreate("ColorSelect_Tool", 220, 110, -1, -1)
WinSetOnTop($hGUI, "", 1)
$hColor = GUICtrlCreateLabel("", 0, 0, 50, 50)
$hSelectColorFromScreen = GUICtrlCreateButton("Select Color from Screen", 70, 0)
$hHex = GUICtrlCreateInput("", 1, 70, 100, -1, $ES_READONLY)
GUICtrlSetBkColor($hHex, 0xFFFFFF)
GUISetState()
While 1
    If GUIGetMsg() = $hSelectColorFromScreen Then
        Do
            If PixelGetColor(MouseGetPos(0), MouseGetPos(1)) <> $xColor Then
                $xColor = PixelGetColor(MouseGetPos(0), MouseGetPos(1))
                GUICtrlSetBkColor($hColor, $xColor)
                GUICtrlSetData($hHex, "0x" & StringRight(Hex($xColor), 6))
            EndIf
        Until _IsPressed(01)
    EndIf
    If GUIGetMsg() = -3 Then
        Exit
    EndIf
WEnd

Note how it only changes if the color under the mouse changes, rather than every time the loop iterates.

Posted

Well I need it because if I can get the bkg color of the label in hex i can compare it to the hex values written in my ini and then determine if I need to change the color.

Its very simple..

Posted

You shouldn't need to do that.

Have something like:

$currentColor = ""

; Put other code here, then when you would normally change the color:

If $currentColor <> $colorYouWantToChangeItTo Then
     GUICtrlSetBkColor($hLabel, $colorYouWantToChangeItTo)
     $currentColor = $colorYouWantToChangeItTo
EndIf

Regards,Josh

Posted

No.

thats not going to work for my situation! muttley

I already explained that I am going to have to get the color off my label bkg first.

And the only way I can think of I PixelGetColor(). But for some strange reason, you don't have the option to have it reuturn in hex.

Posted

But you didn't explain.... why do you need to get the color? Set it to something arbitrary, and when it does the If statement like I showed above, it will automatically change it.

Would you care to post code?

Regards,Josh

Posted

#include <guiconstants.au3>
#include <misc.au3>

$font_Color = iniread(@ScriptDir & "\temp.dat", "font", "color", "0x000000")

$gui = guicreate("", 300, 300)
$ChooseTextColor = GUICtrlCreateLabel("", 30, 30, 30, 30)
GUICtrlSetBkColor(-1, $font_Color)

GUISetState()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit 0
        Case $msg = $ChooseTextColor
                $hex = _ChooseColor(2, $font_Color, 2, $gui)
                If $hex = -1 Then
                Else
                IniWrite(@ScriptDir & "\temp.dat", "Font", "Color", $hex)
                EndIf
    EndSelect
        
    $return_Color = IniRead(@ScriptDir & "\temp.dat", "Font", "Color", "0x000000")  
        GUICtrlSetBkColor($ChooseTextColor, $return_Color)
Wend

this is what my ini looks like at the beginning:

[font]
color=0x000000

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