userform resize

my apologies for this thread if it already exists. I was unable to find anything regarding this subject.

in a vba userform, how do you make the userform size to change by stretching with the mouse or maximized to the screen on load and possibly a percentage of that maximize? Most if not all of the information I find is about using a command button to control this which I have tested but it would be better if the form sized itself based on the resolution of the users machine, either by a different screen resolution or monitor size. The methods noted in most of the forums and videos around anything except Bentley are not available in MVBA such as Application.WindowState. If I could get the size of the active application (ie, MicroStation) I could at least work with that.

Any ideas?

Thanks,

Mark W.

Parents Reply
  • Mark,

    Though it might offend some people's delicate sensibilities - there is a way to do what are looking for with vba and various api declarations/calls.  In my opinion, one would only go through the trouble and time to do this if the form absolutely must be resizable.

    1. To make a vba form resizable by the user, see Chip Pearson's thorough treatment here: http://www.cpearson.com/Excel/FormControl.aspx Note that if you need to update any of the form's controls size after a form resize you can handle the Userform_Resize() event  inside the userform code-behind.

    2. To query the Microstation application window size you need to first get the window handle (hwnd) of the main window with this MDL API declaration and call:

    Private Declare Function mdlNativeWindow_getMainHandle Lib "stdmdlbltin.dll" (ByVal iScreen As Long) As Long
    
    '// Sample usage
    dim msHwnd as long: msHwnd = mdlNativeWindow_getMainHandle(0&)

    Then you need to call the windows API function GetWindowRect() http://allapi.mentalis.org/apilist/GetWindowRect.shtml to obtain the window size in screen pixels.  Not out of the woods yet, because vba units are not pixels, but points.  In all the cases I have seen, 1 pixel = 0.75 point, if you have an exotic graphics card/driver setup that might not be the case.

    Hope it helps,

    James

Children