06-14-2020 04:51 PM
When you open a LabVIEW VI, the standard behavior is for it to open up the same size as when it was last saved. Is there a way to programatically read this default size of the displayed area?
I've dug through the VI/Front Panel properties and invoke methods with no luck. I've yet to find a property that is both un-changing with runtime size changes and reflects the size of the visible portion of the front panel. Ultimately I'm trying to use this to size a window hosting a subpanel based on the hosted control's default size -- backup plan is to cache size on first open (seems like overkill) or to hardcode size info (painful to config and maintain).
Solved! Go to Solution.
06-14-2020 05:33 PM
Well, there are several things you can do (depending on just what you want to achieve). This list isn't exhaustive, since I do limited "playing around with Front Panel sizes", but I have done the following:
Bob Schor
06-14-2020 07:26 PM
One of these 4 items is probably what you're looking for:
06-16-2020 05:45 PM
Thanks for the suggestion, but unfortunately I can't use decorations in this situation: these controls will be resizeable (part of the reason I'm looking for the initial default size), and will be using splitters in many cases.
06-16-2020 05:59 PM
Thanks for the suggestions, but unfortunately none of these will work in my situation, but you did bring to my attention that I forgot to enable VI Scripting after installing 2020 (and therefore overlooked a few options)!
I've tried each of the properties you've mentioned, however they each change with runtime resizes so they can't be used to reliably return default values. Even if I didn't resize, subpanels need to be a few panels larger than controls bounds in order not to miss any pixels, which then leads to the control (in memory) being increased in size, which leads to a cycle of windows getting larger with each rendering of a control.
Annyway...I think I'm going to settle on caching control size on first open, since I suspect there isn't an available property for getting initial default front panel size.
06-16-2020 08:16 PM
Another idea, though I know it's not exactly what you're looking for, is you could set the minimum panel size of the VIs you are loading. Then you can check the minimum size of the front panel and set your subpanel to be at least that size before you insert the VI.
Also, are you using MGI Panel Manager? If not, I highly recommend it - I think it makes subpanels a bit easier to work with.
06-17-2020 03:35 AM
Prettypwines idea is good, setting VI min-size would "find a property that is both un-changing with runtime size changes and reflects the size of the visible portion of the front panel."
06-17-2020 07:43 AM
Thanks for the minimum panel size suggestion -- I had considered this already, but the issue with this is that it would then make the initial (and ideal) size the same as the minimum, so that if the control happened to be shrunk at runtime it wouldn't scale properly down.
Anyway, I'm now just caching the VI.FP.PanelBounds after the first open of any control VI, and this seems to be working well so far.
(As for MGI Panel Manager, I've already got my own wrapper functions to simplify working with these panels, but might very well take a look at it next time!)
06-17-2020 07:52 AM
For completeness, calling a VI that does this before attaching each control seems to be doing the trick (so far):
06-17-2020 01:54 PM
Maybe if you set the called VI to "preallocated reentrant" and spawned a new clone for each call it would always return the default "saved" panel size. I'm guessing the panel itself would also lose any post-runtime user size changes. A roundabout way to accomplish what you are looking for is maybe to have the very first spawned clone as the "master VI" (keep track of reference, do not close/release) and all subsequent clones are only quickly spawned (maybe set as hidden or transparent), property read of default panel size, then the reference destroyed.
Cached approach is probably easier; but like you say the default panel size has to be stored somewhere in the VI itself. The reentrant clone approach is the only way I can think to get at it at runtime.