Contributed by: Wayne Swanson
When placing control objects like a toolbar etc in a VisPro program it can get to be difficult to locate them when the user resizes. VisPro resizes all the objects in the window but they are all proportionally larger or smaller depending on what size the window is being set at (larger or smaller).
Suppose you have a row of buttons set up as a toolbar with bitmaps on them and you want to keep them at 30x30 pixels in size. When the window is resized they may be 40x40 instead of the size you want and if you resize them manually... how do you know where the top of the window is (If you want it attached just under the menu). The "getsize" call to your window includes the titlebar and menu so how do we get down to the window portion of the window accurately?
One way to do it is to add a free-form window control to the program that fills the usable part of the form. You could use any control I suppose but the free-form window is a good choice because it can kill a couple of birds with the same stone. In other words, it will do something else useful if you need it besides just being a sizing template.
In the following snippet we'll get the size of the free-form window (ControlID = 1050) and subtract 30 (our button height) to set the toolbar buttons (ControlID's 1001-1010) at the top of the form window. Using the numbers of the button control ID's we can obtain a multiplier that will allow us to place our buttons in sequence and incremented by the 30 pixel spacing we need.
Here are your prerequisites when using this snippet:
/* Get free-form window control size */
/* "sizery" is equal to the interior height of the window */
Parse Value VpItem(window,1050,'ITEMSIZE') With sizerx sizery
/* Place buttons using their own ID's to increment the x starting */
/* point and the free-form windows sizery-30 for the y starting point */
Do index = 1001 To 1010
Call VpItem window,index,'SETITEMPOS', (index-1001)*30, sizery-30, 30, 30
End