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.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

move a graph legend

How do you programmatically reposition a graph legend in CVI?  Ideally it would be nice to drag and drop the legend at runtime, seeing that the UI editor provides this feature.

0 Kudos
Message 1 of 4
(3,871 Views)

Graph legend can be programmatically moved and sized like all other controls by calling SetCtrlAttribute with the appropriate attribute: ATTR_LEGEND_TOP, _LEFT, _HEIGHT and _WIDTH. You can search for samples\usering\graphlegend example that shows how to move graph legend.

 

As per interactively move the legend, CVI comes with the Run-Time Movable Controls instrument that implements the ability to interactively move controls on the screen, but unfortunately this does not permit to move the graph legend alone. Since the instrument comes with the source code, you may consider to edit the instrument adding the ability to move the graph legend. I cannot evaluate at the moment how difficult this task can be. If you want to see how the instrument works you can take a look at samples\userint\custctrl\movectrl\movedemo.cws example.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 4
(3,855 Views)

I too wanted to give my users the ability to move the legend around.  It's not directly possible, as Roberto said.

 

However, I came up with a workaround using double-click event (and others) and drawing a target outline.  You simply double-click the legend where it is and a red box appears around it.  Then move your mouse to where you want it to be placed.  Left-click once and you're done.

 

On slower machines, this may not work that great, as I continuously redraw the red outline as you move to your target.

 

Have a look.

Message 3 of 4
(2,431 Views)

I was looking for a solution to move the legend interactively. The workaround suggested by ElectroLund  is a good solution and I have integrated it into my code. It works well. Thank you.

0 Kudos
Message 4 of 4
(1,598 Views)