Jump to content

checkbox & Sliderbar


 Share

Recommended Posts

Helo All,

i newbie here, can anyone help for complete below script, i dunno why the script can work for checkbox1 only. can anyone help for make this script work for all func ( checkbox1, checkbox2 & Slidebar )

sorry my english no so good, hope u all can understand.

#RequireAdmin
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
#include <WinAPI.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Process.au3>
#NoTrayIcon

Global $slider1

GUICreate("Test Checkbox and Slider Bar", 370, 400, 100, 100)  ; will create a dialog box
GUISetBkColor(0xFFFBF0)  ; will change background color
GUISetState(@SW_SHOW)
$hTab = GUICtrlCreateTab(5, 10, 360, 380)

$hTab0 = GUICtrlCreateTabItem("Tab 01")
    GUICtrlCreateGroup("", 15, 35, 120, 80)
    $cb1 = GUICtrlCreateCheckbox("CheckBox 1", 25, 50, 100, 20)
    $cb2 = GUICtrlCreateCheckbox("CheckBox 2", 25, 70, 100, 20)
    GUICtrlCreateGroup("", -99, -99, 1, 1)  ;close group

    GUICtrlCreateGroup("", 140, 35, 215, 80)
    GUICtrlCreateLabel("Test InputBox ", 150, 50)
    $InputBox = GUICtrlCreateInput("0", 220, 50, 100, 20)
    GUICtrlCreateGroup("", -99, -99, 1, 1)  ;close group
    GUICtrlCreateLabel("Test Sliderbar ", 150, 80)
    
    GUICtrlCreateLabel("Status of CheckBox : ", 20, 130)
    GUICtrlCreateLabel("CheckBox 1 : ", 30, 145)
    GUICtrlCreateLabel("CheckBox 2 : ", 30, 160)
    
GUICtrlCreateTabItem("")

Checkbox1()
Checkbox2()
Slidebar()

Func Checkbox1()
while 1
$nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cb1       
        if BitAnd(GUICtrlRead($cb1), $GUI_CHECKED) == $GUI_CHECKED Then
            GUICtrlCreateLabel("Checked ", 100, 145)
        Else
            GUICtrlCreateLabel("Unchecked ", 100, 145)
        EndIf
    EndSwitch   
WEnd
EndFunc

Func Checkbox2()
    while 1
$nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cb2       
        if BitAnd(GUICtrlRead($cb2), $GUI_CHECKED) == $GUI_CHECKED Then
            GUICtrlCreateLabel("Checked ", 100, 160)
        Else
            GUICtrlCreateLabel("Unchecked ", 100, 160)
        EndIf
    EndSwitch   
    WEnd    
EndFunc

Func Slidebar()
    $slider1 = GUICtrlCreateSlider(220, 80, 100, 20)
    GUICtrlSetLimit(-1, 500, 0)     ; change min/max value
    GUISetState()
    GUICtrlSetData($slider1, 0)     ; set cursor    
    Do
        $msgslider = GUIGetMsg()        
        If $msgslider = $slider1 Then
            GUICtrlCreateLabel(GUICtrlRead($slider1), 325, 80)
        EndIf
    Until $msgslider = $GUI_EVENT_CLOSE
EndFunc
Link to comment
Share on other sites

  • Moderators

thienfu,

Edit: Please do NOT double post in different forums - it is one of things that we really do not like. :mellow:

You need to put the check for both checkboxes into the one While...WEnd loop. You can check for the slider value constantly, not just when it sends a message. Your code then looks something like this: :P

;#RequireAdmin
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
#include <WinAPI.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Process.au3>
;#NoTrayIcon

Global $slider1

GUICreate("Test Checkbox and Slider Bar", 370, 400, 100, 100)  ; will create a dialog box
GUISetBkColor(0xFFFBF0)  ; will change background color
GUISetState(@SW_SHOW)
$hTab = GUICtrlCreateTab(5, 10, 360, 380)

$hTab0 = GUICtrlCreateTabItem("Tab 01")
    GUICtrlCreateGroup("", 15, 35, 120, 80)
    $cb1 = GUICtrlCreateCheckbox("CheckBox 1", 25, 50, 100, 20)
    $cb2 = GUICtrlCreateCheckbox("CheckBox 2", 25, 70, 100, 20)
    GUICtrlCreateGroup("", -99, -99, 1, 1)  ;close group
    $slider1 = GUICtrlCreateSlider(220, 80, 100, 20)
    GUICtrlSetLimit(-1, 500, 0)     ; change min/max value
    $hLabel = GUICtrlCreateLabel(GUICtrlRead($slider1), 325, 80, 30, 20)

    GUICtrlCreateGroup("", 140, 35, 215, 80)
    GUICtrlCreateLabel("Test InputBox ", 150, 50)
    $InputBox = GUICtrlCreateInput("0", 220, 50, 100, 20)
    GUICtrlCreateGroup("", -99, -99, 1, 1)  ;close group
    GUICtrlCreateLabel("Test Sliderbar ", 150, 80)

    GUICtrlCreateLabel("Status of CheckBox : ", 20, 130)
    GUICtrlCreateLabel("CheckBox 1 : ", 30, 145)
    GUICtrlCreateLabel("CheckBox 2 : ", 30, 160)

GUICtrlCreateTabItem("")

$iLastSlider = 0

While 1

    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cb1
            If BitAnd(GUICtrlRead($cb1), $GUI_CHECKED) = $GUI_CHECKED Then
                GUICtrlCreateLabel("Checked ", 100, 145)
            Else
                GUICtrlCreateLabel("Unchecked ", 100, 145)
            EndIf
        Case $cb2
            If BitAnd(GUICtrlRead($cb2), $GUI_CHECKED) == $GUI_CHECKED Then
                GUICtrlCreateLabel("Checked ", 100, 160)
            Else
                GUICtrlCreateLabel("Unchecked ", 100, 160)
            EndIf
    EndSwitch

    ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    $iCurrSlider = GUICtrlRead($slider1)
    If $iCurrSlider <> $iLastSlider Then
        GUICtrlSetData($hLabel, $iCurrSlider)
        $iLastSlider = $iCurrSlider
    EndIf
    ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

WEnd

You need the $iCurrSlider/$iLastSlider code or the label flashes as it is updated every pass through the loop. Try replacing the section between the <<<<<<<<<<<<< with a simple GUICtrlSetData($hLabel, $slider1) and see what happens. :party:

Ask if anything is unclear. :party:

M23

Edited by Melba23

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

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