Graywalker Posted September 2, 2010 Posted September 2, 2010 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. expandcollapse popup; 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
Valuater Posted September 2, 2010 Posted September 2, 2010 (edited) Might want to have a look at this... ButtonHover.au3 with button pics http://www.autoitscript.com/forum/index.php?showtopic=38726&hl=buttonhover&st=0 8) Edited September 2, 2010 by Valuater
Malkey Posted September 3, 2010 Posted September 3, 2010 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. expandcollapse popup; 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
Graywalker Posted September 3, 2010 Author Posted September 3, 2010 "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). expandcollapse popup; 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
Graywalker Posted September 3, 2010 Author Posted September 3, 2010 Might want to have a look at this... ButtonHover.au3 with button picshttp://www.autoitscript.com/forum/index.php?showtopic=38726&hl=buttonhover&st=08)Thanks! Very nice!
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now