LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

I need to make a snap-slider

I'm having trouble coming up with a simple way to create a snap-slider.  This is a slider control that snaps to a particular value (zero, in my case) when the mouse button is released, but produces the value of the slider while it's held down and dragged around.

Any ideas?  Thanks!
0 Kudos
Message 1 of 14
(4,331 Views)
Hi Lee_Jay,

You can handle two seperate events for the slide: value change and mouse up. In the mouse up event set the value back to zero. Please refer to the attached example VI (8.2).

If you want to make the snap-slide reusable you must make an XControl out of it.

Hope this helps.

PO
Message 2 of 14
(4,311 Views)
You probably need to maintain a shift register for the slide focus so the slide resets even if we grab the slider and move it slightly off the control during operation. While the slide keeps the focus, a mouse up will not trigger a reset as desired if the mouse up occurs outside the control!
 
WIth the slide focus in a shift register, you can use a "Pane: mouse up" and reset if the focus was still on the slide. You also need to cover the case where the mouse drags outside ("VI: mouse leave") the VI and then gets released.
 
Here's a quick example (LV 8.0).
Message 3 of 14
(4,294 Views)
Thank you both for your help.

I added pane-mouse up to the event handling, and that works, but I can't find a way to determine a mouse up if you've left the VI or the application.  I'm not sure it's required since this particular application will be maximized, but I'm worried about a dual-monitor situation in the future where the mouse up happens on the second monitor while the application is maximized on the first.  How do I handle a mouse up when outside the VI or application?

0 Kudos
Message 4 of 14
(4,275 Views)
Hi Altenbach,

Thanks for the extra info. I missed out on the other two cases.

I tried running your VI, and the "VI: Mouse Leave" event does not have the desired effect. I put probes and can see the values flow, but the front panel does not reset the slider to zero when the mouse leaves the VI. Instead the slider continues to change value with the motion of the mouse.

I think it is happening because when the mouse is leaving the VI, it is still holding onto the slider. Hence if you continue to move the mouse after leaving the VI, the slider continues to update and does not reset to zero when you release the mouse. I slightly modified your VI and used a second shift register to remember that the mouse has left the front panel. I may be missing something and there may be an easier way to do this.



Message 5 of 14
(4,271 Views)
Here is the modified VI (8.2).

I did a quick fix and the code does not follow all the coding guidelines Smiley Happy

Message 6 of 14
(4,269 Views)


Prashant Oswal wrote:
I tried running your VI, and the "VI: Mouse Leave" event does not have the desired effect. I put probes and can see the values flow, but the front panel does not reset the slider to zero when the mouse leaves the VI. Instead the slider continues to change value with the motion of the mouse.

Yes, but that's the desired effect. Even if the mouse leaves the front panel while moving the slider, the slide should NOT reset, because it still is under mouse control. Only of you do a mouse-up outside the front panel, the slider should reset to zero. I think this is the preferred behavior and my example perfectly works like that under LabVIEW 8.0. Unfortunately, something changed in 8.2+ and it no longer resets the scale when you do a mouse-up outside the window.
 
It might be interesting to know why this behavior changed and we must find a workaround. It is less of a problem if the panel is maximized, which seems to be the case in the described application.
 
Your fix is not ideal and causes very undesirable behavior if you grab the slider and drag outside the VI window. It will constantly flicker. Try it! Grab the slider, then move vertically down outside the window, then, (with the mouse still pressed) move left and right.
 
 
 
Message 7 of 14
(4,263 Views)
I had already seen the flicker and hence had mentioned that I did a quick fix Smiley Happy.

Yeah, it would be interesting to know why the behavior has changed in 8.2
Message 8 of 14
(4,260 Views)
I really appreciate both of you taking the time to help me.

I've worked on this, and have come to two stumbling blocks.

1)  The pane-mouse up event work in my test VI, but not in the XControl.  I don't know why.  This is my first XControl.

2)  When I update the XControl inside my test VI, for example by changing the limits, it reverts back to the values set in the XControl.  Again, I don't know why.  It acts like a strict type-def, but I don't know how to change it in the XControl

I've attached my test VI, and my XControl project.  I'd appreciate any help you could provide.
Download All
Message 9 of 14
(4,231 Views)
Hi Lee_Jay,

Can you save your VI to version 8.2? I am working in 8.2 and your version is 8.5.

Message 10 of 14
(4,219 Views)