Basic GUI button that changes color / toggles when pressed? Like an "on / off" ?
Basic GUI button that changes color / toggles when pressed? Like an "on / off" ?
I was thinking either simply changing the color from when pressed the text is green = active and when toggled off = red. Perhaps would be cool to have an actual on off switch image but at this point i Just need a visual indication of whether it's enabled or disabled. I'm also not sure how to have a GUI button toggle to have a function when pressed then toggle to do nothing when pressed again? Thanks!
Re: Basic GUI button that changes color / toggles when pressed? Like an "on / off" ?
You can use a picture control as button ( use a g_label ) , if you just want text to indicate on/off there is a way using two buttons in the same location see the example.
Code: Select all
gui ,add,button, x10 y10 vbutton_on w50 h50 gchange,on
gui ,add,button, x10 y10 vbutton_off w50 h50 gchange,off
GuiControl, hide,button_on
Gui, show
return
alert:
soundbeep 600
return
change:
t_on:=!t_on
if t_on
{
GuiControl, hide,button_off
GuiControl, show,button_on
SetTimer, alert,200
}
else
{
GuiControl, hide,button_on
GuiControl, show,button_off
SetTimer, alert,off
}
return
esc::exitapp
Re: Basic GUI button that changes color / toggles when pressed? Like an "on / off" ?
Progress control have color option, which one can bet set using GuiControl command. Also GuiControl command can disable control.
(see: https://autohotkey.com/docs/commands/GuiControl.htm)
Here's a draft to help you start:
(see: https://autohotkey.com/docs/commands/GuiControl.htm)
Here's a draft to help you start:
Code: Select all
Gui, Add, Progress, x3 y58 w294 h5 vMyProgress cGreen, 100
Gui, Add, Button, x3 y3 w294 h54 vMyButton gTEST, blabla ; TEST subroutine will be triggered as soon as button will be clicked. see: https://autohotkey.com/docs/commands/Gui.htm#label
Gui, Show, w400 h400
return
TEST: ; TEST subroutine
MsgBox % "You clicked " . A_GuiControl
GuiControl, +cred, MyProgress ; set MyProgress progress GUI control ''c'' (color) option to be red using GuiControl command
GuiControl, Disable, MyButton ; disabled MyButton button
return
Re: Basic GUI button that changes color / toggles when pressed? Like an "on / off" ?
Thanks folks! I'll try to tinker with both examples. Appreciate it.
Re: Basic GUI button that changes color / toggles when pressed? Like an "on / off" ?
Code: Select all
BS_PUSHLIKE := 0x1000
Gui Add, CheckBox, %BS_PUSHLIKE% r2 vB1 gBtn, This button toggles when you click it.
Gui Add, CheckBox, %BS_PUSHLIKE% r2 vB2 gBtn -Theme, So does this button.
Gui Add, Button, r1.2 vB3 gBtn, This button doesn't.
Gui Show
GuiClose() {
ExitApp
}
Btn() {
GuiControlGet v,, %A_GuiControl%
MsgBox % A_GuiControl "=" v
}
- FanaticGuru
- Posts: 1907
- Joined: 30 Sep 2013, 22:25
Re: Basic GUI button that changes color / toggles when pressed? Like an "on / off" ?
Below is a link to a nice example and tutorial complete with images to download for the buttons.mrsnakers wrote:Perhaps would be cool to have an actual on off switch image...
https://jszapp.com/make-beautiful-graph ... ines-less/
FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
Re: Basic GUI button that changes color / toggles when pressed? Like an "on / off" ?
example color Green/Red ... ON/OFF
EDIT :
see better short version from user TheDewd below
---------------------------------------------------
EDIT :
see better short version from user TheDewd below
---------------------------------------------------
Code: Select all
;- Color button changes to RED/GREEN ON/OFF
#warn
Modified=20130110
Filename1=Color_Button_Test
setworkingdir,%a_scriptdir%
Gui,2:Font,Cdefault,Fixedsys
Gui,2:Color,Black
z:=""
Gui,2:Add,Progress, x10 y20 w100 h23 Disabled BackgroundRed vC2
Gui,2:Add,Text, xp yp wp hp cYellow BackgroundTrans Center 0x200 vB2 gStart,OFF
Gui,2:Add,Progress, xp yp wp hp Disabled BackgroundGreen vC1
Gui,2:Add,Text, xp yp wp hp cYellow BackgroundTrans Center 0x200 vB1 gStart,ON
Gui,2: Show, x10 y1 w200 h60 ,%filename1%
return
2guiclose:
exitapp
start:
gui,2:submit,nohide
z:=!z
if z
{
GuiControl,2: hide,B1
GuiControl,2: hide,C1
GuiControl,2: show,B2
GuiControl,2: show,C2
msgbox, 262208,ColorButtonTest ,You clicked ON_Green-Button,1
}
else
{
GuiControl,2: hide,B2
GuiControl,2: hide,C2
GuiControl,2: show,B1
GuiControl,2: show,C1
msgbox, 262208,ColorButtonTest ,You clicked OFF_Red-Button,1
}
return
;=================================
Last edited by garry on 27 Mar 2017, 16:14, edited 1 time in total.
Re: Basic GUI button that changes color / toggles when pressed? Like an "on / off" ?
Building on Lexikos' example, you can also use the buttons like the radio control.
Code: Select all
#SingleInstance, Force
BS_PUSHLIKE := 0x1000
Gui, Margin, 10, 10
Gui, Add, Radio, %BS_PUSHLIKE% w120 h23 Group, Radio Button 1
Gui, Add, Radio, %BS_PUSHLIKE% w120 h23, Radio Button 2
Gui, Add, Radio, %BS_PUSHLIKE% w120 h23, Radio Button 3
Gui, Add, Radio, %BS_PUSHLIKE% w120 h23, Radio Button 4
Gui, Add, Radio, %BS_PUSHLIKE% w120 h23 -Theme Group, Radio Button 5
Gui, Add, Radio, %BS_PUSHLIKE% w120 h23 -Theme, Radio Button 6
Gui, Add, Radio, %BS_PUSHLIKE% w120 h23 -Theme, Radio Button 7
Gui, Add, Radio, %BS_PUSHLIKE% w120 h23 -Theme, Radio Button 8
Gui, Show, AutoSize, Example
return
GuiClose() {
ExitApp
}
Re: Basic GUI button that changes color / toggles when pressed? Like an "on / off" ?
Garry -- Your example can be simplified:garry wrote:example color Green/Red ... ON/OFFCode: Select all
;- Color button changes to RED/GREEN ON/OFF #warn Modified=20130110 Filename1=Color_Button_Test setworkingdir,%a_scriptdir% Gui,2:Font,Cdefault,Fixedsys Gui,2:Color,Black z:="" Gui,2:Add,Progress, x10 y20 w100 h23 Disabled BackgroundRed vC2 Gui,2:Add,Text, xp yp wp hp cYellow BackgroundTrans Center 0x200 vB2 gStart,OFF Gui,2:Add,Progress, xp yp wp hp Disabled BackgroundGreen vC1 Gui,2:Add,Text, xp yp wp hp cYellow BackgroundTrans Center 0x200 vB1 gStart,ON Gui,2: Show, x10 y1 w200 h60 ,%filename1% return 2guiclose: exitapp start: gui,2:submit,nohide z:=!z if z { GuiControl,2: hide,B1 GuiControl,2: hide,C1 GuiControl,2: show,B2 GuiControl,2: show,C2 msgbox, 262208,ColorButtonTest ,You clicked ON_Green-Button,1 } else { GuiControl,2: hide,B2 GuiControl,2: hide,C2 GuiControl,2: show,B1 GuiControl,2: show,C1 msgbox, 262208,ColorButtonTest ,You clicked OFF_Red-Button,1 } return ;=================================
Slight modifications added (personal preference)
Code: Select all
#SingleInstance, Force
z := ""
Gui, Margin, 10, 10
Gui, Add, Progress, w160 h28 Disabled BackgroundFF0000 vProgress
Gui, Add, Text, xp yp wp hp cFFFFFF BackgroundTrans 0x201 vText gToggle, OFF
Gui, Show, AutoSize, Example
return
Toggle:
z := !z
Gui, Submit, NoHide
GuiControl, % "+Background" (z ? "008000" : "FF0000"), Progress
GuiControl,, Text, % (z ? "ON" : "OFF")
return
GuiClose:
ExitApp
return
Re: Basic GUI button that changes color / toggles when pressed? Like an "on / off" ?
@TheDewd , thank you , this is really nice and very short
-
- Posts: 498
- Joined: 03 Dec 2018, 20:02
Re: Basic GUI button that changes color / toggles when pressed? Like an "on / off" ?
Very nice. You can actually create an ON/OFF switch with this technique
Code: Select all
#SingleInstance Force
BS_PUSHLIKE := 0x1000
Gui, Margin, 20, 20
Gui, Font, s11
Gui, Add, Text, xm, Toggle:
Gui, Add, Radio, %BS_PUSHLIKE% x+10 w40 h23 -Theme Checked, ON
Gui, Add, Radio, %BS_PUSHLIKE% x+0 w40 h23 -Theme, OFF
Gui, Add, Text, xm, POWER:
Gui, Font, Bold
Gui, Add, Radio, %BS_PUSHLIKE% x+10 w25 h23 -Theme Checked, |
Gui, Add, Radio, %BS_PUSHLIKE% y+0 w25 h23 -Theme, ◯
Gui, Font, Normal
Gui, Show
return
GuiClose:
ExitApp
return
Who is online
Users browsing this forum: No registered users and 130 guests