From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Example Code

Moving Front Panel Controls/Indicators With Mouse While VI Is Running

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Overview: In this VI the front panel control/indicator is moved while the mouse is moving and not after the mouse button has been released.


Description:

This example is based on the  following example: Drag and Drop Controls and Indicators on Front Panel.

The difference is that this example moves the front panel control/indicator while the mouse is moving and not after the mouse button has been released.

This uses an event structure with a "Mouse Move" event to track the position of the mouse and adjust the coordinates of the control/indicator accordingly. This adjustment only occurs when the mouse has been clicked on the control/indicator.


Requirements: LabVIEW 2012 (or compatible). Hardware: none.


Steps to Implement or Execute Code:

1. Run the VI.
2. Click on the Boolean control.
3. Move the mouse.
4. Release mouse.
5. Stop the VI.


Additional Information or References:

 

This example is currently set up to have the Boolean control adjust such that the center of the control moves to the location of the mouse.

 

Move Control Mouse FP.png

 

Move Control Mouse BD.png


 **This document has been updated to meet the current required format for the NI Code Exchange.**

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
joshuatree
Member
Member
on

This looks incredible.  I've been looking to do something like this to allow users to customize their own printed tickets by dragging and dropping from a list of fields.

Can u upload a version for 8.5 or earlier please?

IPTN
Member
Member
on

If you do convert please do so to at least 8.0 thx

Pablop
Member
Member
on

I copied this techinque just to be sure it worked from scratch as well as from the download. Ran into some strange behavioe (bug?) if the boolean's label is turned on and the boolean is small (like the default boolean, 17 x 17). The mouse up event doesn't register! Ha!

~~~~~~~~~~~~~~~~~~~~
Paul Johnson
Renco Encoders, Inc
Goleta, CA
~~~~~~~~~~~~~~~~~~~~
APena
Member
Member
on

Hi joshuatree,

Sorry it's taken me so long to do this, but I've uploaded a version saved in LabVIEW 8.5.

APena
Member
Member
on

Hi Pablop,

Thanks for pointing that out. That is some strange behavior and it seems only to happen when the label is visible. I'm going to look into it a little bit further and file a bug report if necessary. Thanks for bring this to my attention!

Rod42
Active Participant
Active Participant
on

It's because of the offset applied between the mouse position and the position at which you set the object. The object's position is the top left as it appears on the screen (including any visible label and caption). The extent is the distance right and down any part of the object reaches. Add an offset of half of these to the origin and you arrive at a point to the right of the (small) LED and beneath the label, but not actually ON any part of the screen object. Therfore when you mouse up it won't register as an event on the object because the mouse isn't over any part of the object.

As a work around you could terminate the move on 'mouse up' on the pane rather than the object

Also you need to remember that you don't recognise a mouse up if you move the mouse off the pane, so add 'mouse leave' on the pane to the event that stops the object moving.

As another thought, disallow right click menus on the object (Advanced -> Real-Time shortcut menu -> Disable) and only start the moving on a right mouse down (In the event for enabling movement, only set the boolean if button=2). That way the left click actions still work normally.