Page 1 of 1

Show name of checkbox button

Posted: 26 Oct 2016, 05:28
by Tomer
Hi,
I need something very simple,
what ever you choose "Msg1" or "Msg2" it will popup a msg with the name of the checkbox button.

For example:
If I choose "Msg2" and Click "OK",
I will get a msg with "Msg2". (coz is the name of the checkbox button)

what "variable" should I use ?

Thanks!

Code: Select all

#SingleInstance force
#NoEnv
SetWorkingDir %A_ScriptDir%

Gui Add, CheckBox, x15 y18 w120 h23, Msg1
Gui Add, CheckBox, x16 y54 w120 h23, Msg2
Gui Add, Button, x128 y34 w75 h23, OK
Gui Show, w217 h97
Return



GuiEscape:
GuiClose:
    ExitApp

; End of the GUI section

Re: Show name of checkbox button

Posted: 26 Oct 2016, 05:40
by TLM
Quick and dirty approach ( there's more than one way ):

Code: Select all

Gui Add, CheckBox, x15 y18 w120 h23 vMsg1 gAssignMsg, Msg1
Gui Add, CheckBox, x16 y54 w120 h23 vMsg2 gAssignMsg, Msg2
Gui Add, Button, x128 y34 w75 h23 gDisplayMsg, OK
Gui Show, w217 h97
Return

AssignMsg:
CurrentMsg := A_GuiControl
Return

DisplayMsg:
ToolTip % CurrentMsg
Return

GuiEscape:
GuiClose:
    ExitApp

Re: Show name of checkbox button

Posted: 26 Oct 2016, 06:54
by Tomer
Thanks but it doesn't take the name from the name text itself,
it take it from the "v-var",

is it possible to take it from the text name itself ?

Thanks

Re: Show name of checkbox button

Posted: 26 Oct 2016, 07:01
by ahkForWork
The way TLM did is the only way that will work.

Re: Show name of checkbox button

Posted: 26 Oct 2016, 07:20
by Tomer
Ok thank you very much!

last:
is it possible to show it only when the checkbox is checked ? if the 2 checkboxs are checked show the names in one msgbox,
etc etc

tnx

Re: Show name of checkbox button

Posted: 26 Oct 2016, 08:33
by wolf_II
Try this:

Code: Select all

#NoEnv
#SingleInstance, Force

Gui, Add, CheckBox, x15 y18 w100 h23, Msg1
Gui, Add, CheckBox, x16 y54 w100 h23, Msg2
Gui, Add, Button, x128 y34 w75 h23, OK
Gui, Show, w217 h97
Return


ButtonOK:
    Gui, +LastFound
    GuiControlGet, CHK_1,, Button1
    ControlGetText, TXT_1, Button1
    GuiControlGet, CHK_2,, Button2
    ControlGetText, TXT_2, Button2
    MsgBox, % (CHK_1 ? TXT_1 : "") "`n"
            . (CHK_2 ? TXT_2 : "") "`n"
Return


GuiEscape:
GuiClose:
ExitApp
I hope that helps.

Re: Show name of checkbox button

Posted: 27 Oct 2016, 04:34
by Tomer
Thanks Wolf, works gr8