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.
becasue VBA Forms are designed to be not resizable by default, an effort to workaround this feature is about finding hacks (there are similar discussions typically related to Excel). Despite of I agree it can be useful, it makes the code more complex and it's a kind of proof you choose wrong tool. VBA is not the right one.
I remember I saw a solution some time ago and it was based on direct Win32 API calls. I don't remember details, but even at this time my feeling was C# WinForms seems to be better solution with far simpler code.
BTW There are Application.Height and Application.Width properties that can be used to check MicroStation windows size. But who knows how it works when multimonitor configuration and/or more MicroStation windows are used...
Labyrinth Technology | dev.notes() | cad.point
I would have to agree that VBA would not be the correct solution regarding this specific need as well as if a professional is running a Multi-Monitor setup for MicroStation. I am unable to find the Application.Height and width properties from within the VBA app in MicroStation but at this point, I may just move past it and reduce the size of the form. Thanks
Mark Winegar said:I am unable to find the Application.Height and width properties from within the VBA app in MicroStation
What MicroStation version do you use? You have not shared this crucial information (see this forum best practices).
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,
Thank you for the information. I will put it to the test. I appreciate your feedback!