Re: How to combine a slider and an edit control in win32lib
- Posted by DerekParnell (admin) May 06, 2009
- 767 views
penpal0andrew said...
If anyone wants to take a try at code which does not wait for the Enter key to be pressed, I would appreciate it.
Assuming Win32lib ...
setUserProperty(EB, "flag", 0) global procedure KeyUp_EB( integer self, integer event, sequence parms ) object val sequence range -- Get the number typed in to the EditBox (EB) val = getNumber(self) -- Check if the user blanked out the whole field. if val = 0 then range = getScrollRange(HSBar) val = range[1] -- use the lowest allowed. end if -- Only change the slider if the editbox value is different from the current position. if val != getScrollPos(HSBar) then -- Get the current range allowed in the scrollbar range = getScrollRange(HSBar) -- Make sure the entered value is in the allowed range. if val >= range[1] and val <= range[2] then -- Set the new position of the 'thumb' setUserProperty(EB, "flag", 1) -- Indicate that the slider is being changed by me setScrollPos(HSBar, val) setUserProperty(EB, "flag", 0) -- Finshed changing the slider. end if end if end procedure setHandler(EB, w32HKeyUp, routine_id("KeyUp_EB"))
And in the paint handler you code something like ...
if equal(getUserProperty(EB, "flag"), {0}) then setText(EB, getScrollPos(HSBar)) end if
The main changes are I now trap the KeyUp event rather than the KeyPress and don't bother checking for VK_RETURN to set the slider. Now setting the slider triggers the paint event, which used to always change the text in the edit box. Now the paint event only changes the editbox text if the paint was not triggered by the editbox setting the slider value.