LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Getting default size of front panel?

Solved!
Go to solution

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).

0 Kudos
Message 1 of 10
(3,609 Views)

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:

  • To make the Front Panel a specific size, and have it not only be that size when run but have the displayed area "surround the bits that you want to show" (perhaps leaving out some debugging Controls and Indicators that you don't need to see at Run Time), I put down a Decoration surrounding the "Visible Front Panel", use "Group" to bind it with the elements inside, then use the wonderful OpenG "Fit VI Window to Largest Decoration" and make this function one of the first to execute.
  • There are property nodes that will return the Bounds of all your monitors, which tell you the left, top, right, and bottom coordinates (with the Primary Monitor having left, top at 0, 0)

Bob Schor

 

 

 

0 Kudos
Message 2 of 10
(3,592 Views)

One of these 4 items is probably what you're looking for:

fpb.png

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 3 of 10
(3,572 Views)

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.

0 Kudos
Message 4 of 10
(3,496 Views)

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.

0 Kudos
Message 5 of 10
(3,492 Views)

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.

0 Kudos
Message 6 of 10
(3,475 Views)

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."

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 7 of 10
(3,446 Views)

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!)

0 Kudos
Message 8 of 10
(3,435 Views)
Solution
Accepted by topic author carls__

For completeness, calling a VI that does this before attaching each control seems to be doing the trick (so far):

 

carls___2-1592398225060.png

 

0 Kudos
Message 9 of 10
(3,433 Views)

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.

0 Kudos
Message 10 of 10
(3,405 Views)