Jump to content

Recommended Posts

Posted

Hi all,

I have a slider that I would like to set a limit that the cursor/selector can reach but can't go higher on the slider bar.

As exemple: the slider is 0 to 100, but I want the selector to stop at 75 so at the 3/4 of the bar.

I tried the set range and set limit, but that  change the end value of the bar.

Thanks in adavanced!

 

$cargocalculatorcargoselectorslider = GUICtrlCreateSlider(100, 170, 550, 30)
GUICtrlSetLimit($cargocalculatorcargoselectorslider, 100, 0)

Posted

like this

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

Example()

Func Example()

    GUICreate("slider", 220, 100, 100, 200)
    GUISetBkColor(0x00E0FFFF) ; will change background color

    Local $iSliderInit = 50         ;slider initial position
    Local $iSliderMaxPercent = 75   ;limit slider position

    Local $idSlider1 = GUICtrlCreateSlider(10, 10, 200, 20)
    GUICtrlSetLimit(-1, 100, 0) ; change min/max value
    GUICtrlSetData($idSlider1, $iSliderInit) ; set cursor
    Local $idButton = GUICtrlCreateButton("Value?", 75, 70, 70, 20)
    Local $idLabel = GUICtrlCreateLabel($iSliderInit, 105, 35, 30, 20)
    GUISetState(@SW_SHOW)


    $iSliderInit = GUICtrlRead($idSlider1)

    While 1
        $iSliderCurrent = GUICtrlRead($idSlider1)
        If $iSliderCurrent <> $iSliderInit then
            GUICtrlSetData($idLabel, $iSliderCurrent)
            $iSliderInit = $iSliderCurrent
        EndIf
    
        Local $idMsg = GUIGetMsg()
        Switch $idMsg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $idButton
                MsgBox($MB_SYSTEMMODAL, "slider1", GUICtrlRead($idSlider1), 2)
            Case $idSlider1
                Local $idSliderPos = GUICtrlRead($idSlider1)
                If $idSliderPos >= $iSliderMaxPercent Then
                    Local $iSliderCustom = InputBox('WARNING! Exceeded '&$iSliderMaxPercent&'%', _
                          'Set Max '&$iSliderMaxPercent&'% or Enter new Value', $iSliderMaxPercent)
                    GUICtrlSetData($idSlider1, $iSliderCustom) ; set cursor
                EndIf
        EndSwitch
    WEnd
    
    Exit
EndFunc   ;==>Example

 

Posted
On 9/22/2020 at 1:29 PM, zeenmakr said:

like this

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

Example()

Func Example()

    GUICreate("slider", 220, 100, 100, 200)
    GUISetBkColor(0x00E0FFFF) ; will change background color

    Local $iSliderInit = 50         ;slider initial position
    Local $iSliderMaxPercent = 75   ;limit slider position

    Local $idSlider1 = GUICtrlCreateSlider(10, 10, 200, 20)
    GUICtrlSetLimit(-1, 100, 0) ; change min/max value
    GUICtrlSetData($idSlider1, $iSliderInit) ; set cursor
    Local $idButton = GUICtrlCreateButton("Value?", 75, 70, 70, 20)
    Local $idLabel = GUICtrlCreateLabel($iSliderInit, 105, 35, 30, 20)
    GUISetState(@SW_SHOW)


    $iSliderInit = GUICtrlRead($idSlider1)

    While 1
        $iSliderCurrent = GUICtrlRead($idSlider1)
        If $iSliderCurrent <> $iSliderInit then
            GUICtrlSetData($idLabel, $iSliderCurrent)
            $iSliderInit = $iSliderCurrent
        EndIf
    
        Local $idMsg = GUIGetMsg()
        Switch $idMsg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $idButton
                MsgBox($MB_SYSTEMMODAL, "slider1", GUICtrlRead($idSlider1), 2)
            Case $idSlider1
                Local $idSliderPos = GUICtrlRead($idSlider1)
                If $idSliderPos >= $iSliderMaxPercent Then
                    Local $iSliderCustom = InputBox('WARNING! Exceeded '&$iSliderMaxPercent&'%', _
                          'Set Max '&$iSliderMaxPercent&'% or Enter new Value', $iSliderMaxPercent)
                    GUICtrlSetData($idSlider1, $iSliderCustom) ; set cursor
                EndIf
        EndSwitch
    WEnd
    
    Exit
EndFunc   ;==>Example

 

Thanks a lot! Working like a charm!

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...