Shikuri Posted February 10, 2015 Share Posted February 10, 2015 Hello guys. I want to make toggle button C(ON/OFF), but im totally green there. Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted February 10, 2015 Moderators Share Posted February 10, 2015 Did you try searching the forum?? A simple search of toggle button or on/off button returns a number of threads. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 10, 2015 Moderators Share Posted February 10, 2015 Shikuri,Welcome to the AutoIt forums. You could do it like this:#include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <ButtonConstants.au3> $hGUI = GUICreate("Test", 500, 500) $cButton = GUICtrlCreateCheckbox("On", 10, 10, 80, 30, $BS_PUSHLIKE) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cButton Switch GUICtrlRead($cButton) Case $GUI_CHECKED GUICtrlSetData($cButton, "Off") MsgBox($MB_SYSTEMMODAL, "Button", "ON") Case Else GUICtrlSetData($cButton, "On") MsgBox($MB_SYSTEMMODAL, "Button", "OFF") EndSwitch EndSwitch WEndAs you are a complete beginner to AutoIt (and we all were at one point, so no problem at all) reading the Help file (at least the first few sections - Using AutoIt, Tutorials and the first couple of References) will help you enormously. You should also look at this excellent tutorial - you will find other tutorials in the Wiki (the link is at the top of the page). M23 guiltyking and CoffeeJoe 1 1 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Cynagen Posted February 11, 2015 Share Posted February 11, 2015 M23, I'm assuming because they admit they're new you didn't want to blow their mind with a Ternary setup? #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <ButtonConstants.au3> $hGUI = GUICreate("Test", 500, 500) $cButton = GUICtrlCreateCheckbox("OFF", 10, 10, 80, 30, $BS_PUSHLIKE) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cButton GUICtrlSetData($cButton,(GUICtrlRead($cButton) = $GUI_CHECKED) ? "ON" : "OFF") EndSwitch WEnd GoogleGonnaSaveUs 1 Blah, blah, blah... lip service... lip service.Working on a number of projects right now, just waiting for my time to post them here on AutoIt forums. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 11, 2015 Moderators Share Posted February 11, 2015 Cynagen,Not entirely - my suggested solution also allows for other code to be run when the button is actioned. Whereas merely allowing the script to rename the button makes the whole thing a bit of a "self-licking lollipop". M23 Cynagen 1 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
SadBunny Posted February 12, 2015 Share Posted February 12, 2015 Cynagen, Not entirely - my suggested solution also allows for other code to be run when the button is actioned. Whereas merely allowing the script to rename the button makes the whole thing a bit of a "self-licking lollipop". M23 ? kylomas and czardas 2 Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
Cynagen Posted February 12, 2015 Share Posted February 12, 2015 (edited) Cynagen, Not entirely - my suggested solution also allows for other code to be run when the button is actioned. Whereas merely allowing the script to rename the button makes the whole thing a bit of a "self-licking lollipop". M23 I get that M23, you can still include an IF afterwards, it's just switching the button's display can be a simple 1-liner with the way I've done mine. ? What M23 means by "self-licking lollipop" is that my code does nothing more than actually change the button text (which is what the user was originally asking for) in the simplest means using a Ternary operation. M23's breaks down what mine does into the basics (Ternary operations are effectively self-contained IF statements) for how it actually works on the inside and allows for extra code to be inserted to react to the change not only visually but with any other code that is inserted into the IF statement. For somebody just learning AutoIt, mine is pretty and takes care of the visuals, but doesn't address how you want the button to react, M23's does. I just like to minimize the amount of code I actually write to do something is all. Edited February 12, 2015 by Cynagen Blah, blah, blah... lip service... lip service.Working on a number of projects right now, just waiting for my time to post them here on AutoIt forums. Link to comment Share on other sites More sharing options...
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