02-17-2016 12:28 PM
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.
02-18-2016 03:42 AM
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.
05-07-2018 11:02 AM
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.
03-22-2021 08:19 AM
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.