Jump to content

'15 Colored Buttons Example.au3'


Recommended Posts

taurus905,

I didn't want to continue adding into the wrong forum but, this is one way of how to replace variables ($a, $b, $c . . . $m, $n, $o) into array like $Key[16].

Danny35d

#include <GUIConstants.au3>
; 15 Colored Buttons Example.au3
Dim $Key[16]
Local $Row = 5, $Column = 5, $Color = -1
Local $BtnColors[16] = [15, '0xff0000', '0x00ff00', 'x0000ff', '0xffff00', '0xffffff', '0xffaa00', '0xaaff00', '0x00aaff', '0xffffaa', '0xdddddd', '0xffee00', '0xccff00', '0x00ddff', '0xffeedd', '0x000000']
GUICreate("15 Colored Buttons Example", 300, 100)

For $x = 1 To 15
    $ret = _GUICtrlCreateColorButton("test" & $x, $Column, $Row, 50, 20, $BtnColors[$x], $Color)
    $Key[$x] = $ret[0]
    $Column += 60
    If $Column > 245 Then $Column = 5
    If $Column == 5 Then $Row += 30
    If $x == 14 Or $Column == 125 Then
        $Color = '0xffffff'
    Else
        $Color = ''
    EndIf
Next
GUISetState()

Do
    $msg = GUIGetMsg()
    
    For $x = 1 To 15
        If $msg == $Key[$x] Then
            MsgBox(0, "colorbutton pressed", "You pressed cb" & $x, 1)
            ExitLoop
        EndIf
    Next
Until $msg = $GUI_EVENT_CLOSE

;#include-once
;=============================================================================
;
; Function Name:   _GUICtrlCreateColorButton()
;
; Description:   Creates a colored Button
;
; Syntax:         _GUICtrlCreateColorButton($text, $left, $top, $width, $height,$bkcolor[,$fontcolor])
;
; Parameter(s);   $text = The text of the control
;                   $left = The left side of the control
;                   $top = The top of the control
;                   $width = The width of the control
;                   $height = The height of the control
;                   $bkcolor = Backgroundcolor of the control
;                   $fontcolor = [optional] Fontcolor of the control
;
; Return Value(s):  array[1] = used to change colors
;                  array[0] = notifies GUIGetMsg if user clicks
;
; Author:           rakudave <rakudave@gmx.net>
;=============================================================================
Func _GUICtrlCreateColorButton($text, $left, $top, $width, $height, $bkcolor, $fontcolor = -1)
    Local $colbut[2]
    If $fontcolor == -1 Then $fontcolor = 0x000000
    $colbut[0] = GUICtrlCreateLabel("", $left, $top, $width, $height, $SS_BLACKRECT)
    GUICtrlCreateLabel("", $left, $top, $width - 1, $height - 1, $SS_WHITERECT)
    GUICtrlCreateLabel("", $left + 1, $top + 1, $width - 2, $height - 2, $SS_GRAYRECT)
    $colbut[1] = GUICtrlCreateLabel($text, $left + 1, $top + 1, $width - 3, $height - 3, $SS_NOTIFY & $SS_CENTER)
    GUICtrlSetBkColor(-1, $bkcolor)
    GUICtrlSetColor(-1, $fontcolor)
    Return $colbut
EndFunc  ;==>_GUICtrlCreateColorButton
I Hope this will help you...

If you have any question about the code just send me a PM or create a new post at v3 Support .

Note:

I modify a little bit the function _GUICtrlCreateColorButton.

1) I changed the value of $fontcolor from 0x000000 to -1

2) Add this line If $fontcolor == -1 Then $fontcolor = 0x000000

I did those changes no because it was worng but, to continue with the way that most of AutoIt user follow.

Danny35d,

I sent a CC of this PM to rakudave so he won't waste his time doing what you already finished.

Thanks to you both, I will finally be able to create a flexible gui with colors.

I think that is so cool. :think:

Thank you also for conforming with the way most others use AutoIt.

I am learning a lot here.

I will post this message in the v3 Support Forum as '15 Colored Buttons Example.au3' along with a link to my other post:

http://www.autoitscript.com/forum/index.ph...ndpost&p=179462

which I mistakenly posted in 'Scripts and Scraps' (which is not a general support forum), in order for other users to find and comment on rakudave's UDF, _GUICtrlCreateColorButton(), and the '15 Colored Buttons Example.au3' (which I took the liberty of giving a name.)

Thank you Danny35d and thank you rakudave. :(

"Never mistake kindness for weakness."-- Author Unknown --"The highest point to which a weak but experienced mind can rise is detecting the weakness of better men."-- Georg Lichtenberg --Simple Obfuscator (Beta not needed.), Random names for Vars and Funcs

Link to comment
Share on other sites

now appear to be "pressed buttons"

#include <GUIConstants.au3>
; 15 Colored Buttons Example.au3
Dim $Key[16]
Local $Row = 5, $Column = 5, $Color = -1
Local $BtnColors[16] = [15, '0xff0000', '0x00ff00', 'x0000ff', '0xffff00', '0xffffff', '0xffaa00', '0xaaff00', '0x00aaff', '0xffffaa', '0xdddddd', '0xffee00', '0xccff00', '0x00ddff', '0xffeedd', '0x000000']
GUICreate("15 Colored Buttons Example", 300, 100, 100, 100)

For $x = 1 To 15
    $ret = _GUICtrlCreateColorButton("test" & $x, $Column, $Row, 50, 20, $BtnColors[$x], $Color)
    $Key[$x] = $ret[0]
    $Column += 60
    If $Column > 245 Then $Column = 5
    If $Column == 5 Then $Row += 30
    If $x == 14 Or $Column == 125 Then
        $Color = '0xffffff'
    Else
        $Color = ''
    EndIf
Next
GUISetState()

Do
    $msg = GUIGetMsg()
    
    For $x = 1 To 15
        If $msg == $Key[$x] Then
            GUICtrlSetStyle($Key[$x], $SS_ETCHEDFRAME)
            MsgBox(0, "colorbutton pressed", "You pressed cb" & $x, 1)
            GUICtrlSetStyle($Key[$x], $SS_NOTIFY + $SS_GRAYRECT)
            ExitLoop
        EndIf
    Next
Until $msg = $GUI_EVENT_CLOSE

;#include-once
;=============================================================================
;
; Function Name:   _GUICtrlCreateColorButton()
;
; Description:   Creates a colored Button
;
; Syntax:         _GUICtrlCreateColorButton($text, $left, $top, $width, $height,$bkcolor[,$fontcolor])
;
; Parameter(s);   $text = The text of the control
;                   $left = The left side of the control
;                   $top = The top of the control
;                   $width = The width of the control
;                   $height = The height of the control
;                   $bkcolor = Backgroundcolor of the control
;                   $fontcolor = [optional] Fontcolor of the control
;
; Return Value(s):  array[1] = used to change colors
;                  array[0] = notifies GUIGetMsg if user clicks
;
; Author:           rakudave <rakudave@gmx.net>
;=============================================================================
Func _GUICtrlCreateColorButton($text, $left, $top, $width, $height, $bkcolor, $fontcolor = -1)
    Local $colbut[2]
    If $fontcolor == -1 Then $fontcolor = 0x000000
    $colbut[0] = GUICtrlCreateLabel("", $left, $top, $width, $height, $SS_BLACKRECT)
    GUICtrlCreateLabel("", $left, $top, $width - 1, $height - 1, $SS_WHITERECT)
    GUICtrlCreateLabel("", $left + 1, $top + 1, $width - 2, $height - 2, $SS_GRAYRECT)
    $colbut[1] = GUICtrlCreateLabel($text, $left + 1, $top + 1, $width - 3, $height - 3, $SS_NOTIFY & $SS_CENTER)
    GUICtrlSetBkColor(-1, $bkcolor)
    GUICtrlSetColor(-1, $fontcolor)
    Return $colbut
EndFunc ;==>_GUICtrlCreateColorButton

8)

NEWHeader1.png

Link to comment
Share on other sites

now appear to be "pressed buttons"

Valuater,

Thanks for the "pressed buttons" effect. I can use that. :)

taurus905

"Never mistake kindness for weakness."-- Author Unknown --"The highest point to which a weak but experienced mind can rise is detecting the weakness of better men."-- Georg Lichtenberg --Simple Obfuscator (Beta not needed.), Random names for Vars and Funcs

Link to comment
Share on other sites

  • 5 weeks later...

I was wondering if it were possible to create a transparent button on top of a colored label.

That way, you could see the color of the label, but be able to click on the button.

taurus905

"Never mistake kindness for weakness."-- Author Unknown --"The highest point to which a weak but experienced mind can rise is detecting the weakness of better men."-- Georg Lichtenberg --Simple Obfuscator (Beta not needed.), Random names for Vars and Funcs

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