Jump to content

Text over Image


Graywalker
 Share

Recommended Posts

Since you can't have buttons with a background color now, I want colored buttons that change and have changeable text... (see this bug- Can't use GUICtrlSetBkColor() in the script.)

Okay, you will have to IMAGINE (or download the attached ones) a few solid .gif image or something similar. Hopefully the below will help get the gist of what I want to do.

; Text over Button
#include <GuiConstants.au3>

Opt("GUIOnEventMode", 1)

$color = "Red"

Global $i = 1

; Create the GUI
$Gui1 = GUICreate("Text over Button",300,300)
GUISetOnEvent($GUI_EVENT_CLOSE,"_Exit")
$button1 = GUICtrlCreatePic("Red.gif",10,12,75,25)
$b1label = GUICtrlCreateLabel("Red",10,12,75,25)
GUICtrlSetOnEvent($button1,"Change")
GUICtrlSetOnEvent($b1label,"Change")

GUISetState(@SW_SHOW)

While 1
    Sleep(100)
WEnd

Func Change()
    $i = $i + 1
    If $i > 3 Then $i = 1
    Select
        Case $i = 1
            GUICtrlSetImage($button1,"Red.gif")
            GUICtrlSetData($b1label,"Red")
        Case $i = 2
            GUICtrlSetImage($button1,"Yellow.gif")
            GUICtrlSetData($b1label,"Yellow")
        Case $i = 3
            GUICtrlSetImage($button1,"Green.gif")
            GUICtrlSetData($b1label,"Green")
    EndSelect
EndFunc

Func _Exit()
    Exit
EndFunc

post-38206-12834583008117_thumb.gif

post-38206-12834583080358_thumb.gif

post-38206-12834583129955_thumb.gif

Link to comment
Share on other sites

Since you can't have buttons with a background color now, I want colored buttons that change and have changeable text... (see this bug- Can't use GUICtrlSetBkColor() in the script.)

....

"This bug" is not a bug when you use GUICtrlSetBkColor() to make the background transparent.

This example disables the pic control and solely uses the label with the transparent background as the button.The three gif images (red, yellow, green) should be in the script directory for this script to work.

; Text over Button
#include <GuiConstants.au3>
#include <WinAPI.au3>
#include <Misc.au3>

Opt("GUIOnEventMode", 1)

Global $i = 1, $color = "Red", $Gui1, $button1, $b1label, $aCtrlInfo

; Create the GUI
$Gui1 = GUICreate("Text over Button", 300, 300)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
$button1 = GUICtrlCreatePic("Red.gif", 10, 12, 75, 25)
GUICtrlSetState(-1, $GUI_DISABLE)
$b1label = GUICtrlCreateLabel("Red", 10, 12, 75, 25, 0x201)
GUICtrlSetBkColor($b1label, $GUI_BKCOLOR_TRANSPARENT)
;GUICtrlSetOnEvent($button1, "Change")
GUICtrlSetOnEvent($b1label, "Change")

GUISetState(@SW_SHOW)

While 1
    Sleep(10)
    $aCtrlInfo = GUIGetCursorInfo()
    If IsArray($aCtrlInfo) Then
        If $aCtrlInfo[4] = $b1label Then
            If $i <> 2 Then ; Avoid continuously setting image
                GUICtrlSetImage($button1, "Yellow.gif")
                GUICtrlSetData($b1label, "Yellow")
                $i = 2
            EndIf
            Sleep(10)
        ElseIf $i <> 1 Then ; Avoid continuously setting image
            GUICtrlSetImage($button1, "Red.gif")
            GUICtrlSetData($b1label, "Red")
            $i = 1
        EndIf
    EndIf
WEnd


Func Change()
    Do
        If $i <> 3 Then
            GUICtrlSetImage($button1, "Green.gif")
            GUICtrlSetData($b1label, "Green")
            $i = 3
        EndIf
        Sleep(10)
    Until Not _IsPressed("01")
    $aCtrlInfo = GUIGetCursorInfo()
    If IsArray($aCtrlInfo) Then
        If $aCtrlInfo[4] = $b1label Then ; Mouse must be over button when released else will not work.
            MsgBox(0, "", " Button pressed", 1, $Gui1) ; <--- When button is pressed properly.
        EndIf
    EndIf
    GUICtrlSetImage($button1, "Red.gif")
    GUICtrlSetData($b1label, "Red")
    $i = 1
EndFunc ;==>Change

Func _Exit()
    Exit
EndFunc ;==>_Exit
Link to comment
Share on other sites

"This bug" is not a bug when you use GUICtrlSetBkColor() to make the background transparent.

This example disables the pic control and solely uses the label with the transparent background as the button.The three gif images (red, yellow, green) should be in the script directory for this script to work.

Thank you! A little bit more complex than what I was looking for, but the theory ( disable the pic and transparent label ) worked great!

I think the "bug" referenced only affected Buttons (making buttons steal default), so making using GUICtrlSetBkColor() wouldn't hurt labels (or any non-button).

; Text over Button
#include <GuiConstants.au3>
#include <WinAPI.au3>
#include <Misc.au3>

Opt("GUIOnEventMode", 1)

Global $i = 1, $color = "Red", $Gui1, $button1, $b1label, $aCtrlInfo

; Create the GUI
$Gui1 = GUICreate("Text over Button", 300, 300)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
$button1 = GUICtrlCreatePic(".\Images\Red.gif", 10, 12, 75, 25)
GUICtrlSetState(-1, $GUI_DISABLE)
$b1label = GUICtrlCreateLabel("Red", 10, 12, 75, 25, 0x201)
GUICtrlSetBkColor($b1label, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetOnEvent($b1label, "Change")

GUISetState(@SW_SHOW)

While 1
    Sleep(10)
WEnd


Func Change()
    $i = $i + 1
    If $i > 3 Then $i = 1
    Select
        Case $i = 1
            GUICtrlSetImage($button1,".\Images\Red.gif")
            GUICtrlSetData($b1label,"Red")
        Case $i = 2
            GUICtrlSetImage($button1,".\Images\Yellow.gif")
            GUICtrlSetData($b1label,"Yellow")
        Case $i = 3
            GUICtrlSetImage($button1,".\Images\Green.gif")
            GUICtrlSetData($b1label,"Green")
    EndSelect

EndFunc ;==>Change

Func _Exit()
    Exit
EndFunc ;==>_Exit
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...