Jump to content

How to make a button with a checkbox


Recommended Posts

  • Moderators

Tyranna,

Can you explain why you wish to have a checkbox on a button? If we understand the purpose, we might be able to suggest an alternative solution - using the $BS_SPLITBUTTON style sounds as if it might fit the bill.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

The Button is going to perform the function, and if the box is checked, then it will be monitored and activated automatically at

specified intervals by the script, so I will not have to push the button manually.  It allows me to perform the function once if I want, but

if I want it to run auto, I can check the box.


 

Link to comment
Share on other sites

  • Moderators

Tyranna,

Why can you not just place the checkbox beside the button?

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

Tyranna,

How about this SplitButton example as "a compact, superior interface"?

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <MsgBoxConstants.au3>
#include <GuiMenu.au3>

$hGUI = GUICreate("Test", 500, 500)

$cSplitButton = GUICtrlCreateButton("Run Auto", 10, 10, 120, 30, $BS_SPLITBUTTON)

GUISetState()

GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cSplitButton
            _Run_Select()
    EndSwitch

WEnd

Func _Run_Select()
    Switch GUICtrlRead($cSplitButton)
        Case "Run Auto"
            MsgBox($MB_SYSTEMMODAL, "Selected", "Auto")
        Case "Run Once"
            MsgBox($MB_SYSTEMMODAL, "Selected", "Once")
    EndSwitch
EndFunc

Func _Run_Menu($hCtrl)

    Local Enum $iOption_1 = 1000, $iOption_2
    Local $hMenu = _GUICtrlMenu_CreatePopup()
    _GUICtrlMenu_InsertMenuItem($hMenu, 0, "Run Auto", $iOption_1)
    _GUICtrlMenu_InsertMenuItem($hMenu, 1, "Run Once", $iOption_2)
    Switch _GUICtrlMenu_TrackPopupMenu($hMenu, $hCtrl, -1, -1, 1, 1, 2)
        Case $iOption_1
            GUICtrlSetData($cSplitButton, "Run Auto")
        Case $iOption_2
            GUICtrlSetData($cSplitButton, "Run Once")
    EndSwitch
    _GUICtrlMenu_DestroyMenu($hMenu)

    _Run_Select()

EndFunc   ;==>List_Insert_Menu

Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $wParam

    Local $tStruct = DllStructCreate($tagNMHDR, $lParam)
    If @error Then Return
    Switch DllStructGetData($tStruct, "Code")
        Case $BCN_DROPDOWN
            _Run_Menu(DllStructGetData($tStruct, "hWndFrom"))
    EndSwitch
EndFunc

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

That is not bad, and it would probably do what i want, but what I am doing is mapping an 2 different images to the same button

depending if a flag is set, the flag is checked from within the message loop, and also the image is changed if it is in auto.

So,

0 and 0 = not active , not auto

0 and 1 = not active ,  auto

1 and 0 =  active , not auto

1 and 1 =  active ,  auto

Really , I wanted a Gold border around the button when selected , No border when not. (For Auto)

A dark image if the flag is not set. And a bright image when is set.

I ended up making 4 images to put on the button, 1 for every state and change it by checking both every time....

 

 

 

 

 


 

Link to comment
Share on other sites

  • Moderators

Tyranna,

Glad you got what you wanted - even if it sounds a bit complicated.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

There are some definite limitations for graphics manipulation in AutoIt.

Thanks for the Split Example , I saved it and will look at it further.  Probably will not use it for this specific project, but I like that functionality.


 

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