Sign in to follow this  
Followers 0
flyingboz

Changing Color of Control

4 posts in this topic

I wrote this code snippet to test where I'm failing - can someone more experienced take a quick look at this - code attempts to change label

text and color - text change works, color change doesn't - using latest build of .103

$dec_color = _ChgLabelColor()
Exit $dec_color

Func  _ChgLabelColor ()

   opt("trayicondebug",1)
   Opt ("GUINotifyMode", 1) 
   Opt("ColorMode",0)
   local   $hwnd = GuiCreate("this is a window",100,100)

;build a sample array of colors to test
   local $test_color = "0x000000,0xFF0000,0x00FF00,0x0000FF,0xFFFFFF"
   local $color = StringSplit($test_color,',')
   
;initialize control
    $text = GUISetControl("label","text",1,1,100,100)
   GuiShow()

;loop through array of colors       
         For $i = 1 to Ubound($color) -1
               sleep(3000)
            GUIWrite($text,0,$color[$i]);  change label text in control         GUISetControlEX($text,0,0,"",$color[$i]) ;change color of control
            GUIShow() ;display results - no expected change of color in text
         Next
        
EndFunc

Reading the help file before you post... Not only will it make you look smarter, it will make you smarter.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Are you sure that your GUISetControlEx is on a NEW line, otherwise it is commented.

I saw..the problem is the color.

Color has to be an numeric value NOT a string!

Edit:

Here is another idea...

$dec_color = _ChgLabelColor()
Exit $dec_color

Func  _ChgLabelColor ()

   opt("trayicondebug",1)
   Opt ("GUINotifyMode", 1) 
   Opt("ColorMode",0)
   local   $hwnd = GuiCreate("this is a window",100,100)

;build a sample array of colors to test
   local $color[5]
   $color[0] = 0x000000
   $color[1] = 0xFF0000
   $color[2] = 0x00FF00
   $color[3] = 0x0000FF
   $color[4] = 0xFFFFFF
   
;initialize control
    $text = GUISetControl("label","text",1,1,100,100)
   GuiShow()

;loop through array of colors       
         For $i = 0 to Ubound($color) -1
               sleep(3000)
            GUIWrite($text,0,$color[$i]);  change label text in control            
            GUISetControlEX($text,0,0,"",$color[$i]);change color of control
         Next
        
EndFunc
Edited by Holger

Share this post


Link to post
Share on other sites

Color has to be an numeric value NOT a string!

From the help file:

Integers (whole numbers) can also be represented in hexadecimal notation by preceding the integer with 0x as in 0x409 or 0x4fff (when using hex notation only 32-bit numbers are valid).

From the changelog detailing build 102:

Added: Strings starting with "0x" are converted from hex when used numerically

Holger, this does seem to be the problem - should I report this as a potential bug?

Is there a way to force the hex string to an integer? I tried number() and Int(), neither succeed.


Reading the help file before you post... Not only will it make you look smarter, it will make you smarter.

Share this post


Link to post
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
Sign in to follow this  
Followers 0