On a MDI form with toolbars and menus, how can one calculate the usable area (height) of the MDI form.
Usable means the area below the toolbar to the bottom of the form.
Printable View
On a MDI form with toolbars and menus, how can one calculate the usable area (height) of the MDI form.
Usable means the area below the toolbar to the bottom of the form.
Hi Randem,
Take a look at http://vbnet.mvps.org/code/helpers/clipcursor.htm. I think this will break down to what you need.
Steve.
Am I missing something?Code:Option Explicit
Dim Wdth As Long, Hght As Long
Private Sub MDIForm_Resize()
Wdth = ScaleWidth
Hght = ScaleHeight
Caption = Wdth & "," & Hght
End Sub
Hi Milk,
Scaleheight will give the entire height of the form, without allowing for Toolbars etc. What Randem requires is the useable area when all this is taken into account.
However, upon reflection it is obvious that a Toolbar has a height in Twips that is independent of Screen resolution. I.e. a toolbar that is 400 twips on my screen (1680 x 1050) will still be 400 twips on a 800 x 600 machine. So some number crunching here in the form should actually cater for all!
Steve.
Are you sure? As far as I can tell they return the usable area. The Caption on the form below shows the returned Scalewidth and ScaleHeight properties.
Yes my friend, I am sure!
Hmmm, how do I get it looking like yours??
ahh, I see that a normal form will take into account the menu, but not the toolbars wheras a MDI form will account for both
Not 100% sure, might be something to do with the size or that fact they are multiple images... the ones I posted are pingsQuote:
Originally Posted by Steve Grant
Hey Milk,
I'm not sure what you mean when you state;
If you look at my jpg's, they all show the same scaleheight (and height) for -Quote:
I see that a normal form will take into account the menu, but not the toolbars wheras a MDI form will account for both
A blank form
A form with a menu
A form with a menu and toolbar.
Of interest is the fact that an MDI form changes its height as Menu components are added, but not toolbars. You were right in post #3 though, that an MDI form does correctly return the required parameters in the Scaleheight property. Randem must be like me, hardly ever use MDI.
:) I did (look at them), the form without a menu is shorter than the other two with a menu. ;)
OMG :blush: You're right, I hadn't noticed the increase in form size when adding the menu on a standard form.
Debug.Print's of a form where I carried out the above test again.
Height - Scaleheight
12735 12225
13035 12225
13035 12225
Thanks for being so observant Milk, though whether we've gone any way to helping Randem, I'm not sure.
He knows what he's doing, when it comes to VB!
In form or screen co-ordinates?Quote:
Originally Posted by randem
You can calculate either by using a combination of the APIs GetWindowRect and GetClientRect. GetWindowRect returns the form size/position in screen co-ordinates. GetClientRect returns the size of the client area (below the menu bar) - which seems to be what you're after. Subtracting the client width from the window width gives you the form's border width/height x2. Once you have the border you can calculate the position of the client area top-left corner in either form or screen co-ordinates. GetClientRect will include the dimensions of any tool/status bars so you'll need to take this into account.
I do this for positioning overlays. Do yu have a specific problem in mind ?
Note: The GetTitleBarInfo API will not provide the information you require, neither will GetSystemMetrics nor SystemParametersInfo.
The problem I had was when using ListView controls on SSTAB containers. When the ListView had a heading the height of the listview changed and had to be recalculated to fit into the assigned area. Being that it was at the bottom of the screen all calculation to fit the controls overflowed the viewing area because of the change.
Thanks all it helped point me in the right direction.
This problem also occurs if you place any object on the MDI form such as a picturebox. Even though you can display over the picturebox the usable area is decreased and that will mess up any sizing calculations based on the new reduced size even though the complete area of the MDI form is usable.
The solution was to load the MDI form then get the usable area (ScaleWidth and ScaleHeight) then dynamically load the PictureBoxes that I needed as to not decrease the ScaleHeight that I held, then use the held ScaleHeight and ScaleWidth to calculate the remaining area that I had to move other controls around each Maximized loaded MDI Child form.