Results 1 to 15 of 15

Thread: [RESOLVED] How to calculate usable screen area height

  1. #1

    Thread Starter
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Resolved [RESOLVED] How to calculate usable screen area height

    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.
    Last edited by randem; Sep 29th, 2007 at 04:28 AM.

  2. #2
    Fanatic Member
    Join Date
    Jul 2007
    Location
    Essex, UK.
    Posts
    579

    Re: How to calculate usable screen area height

    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.

  3. #3
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,448

    Re: How to calculate usable screen area height

    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

  4. #4
    Fanatic Member
    Join Date
    Jul 2007
    Location
    Essex, UK.
    Posts
    579

    Re: How to calculate usable screen area height

    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.

  5. #5
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,448

    Re: How to calculate usable screen area height

    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.
    Attached Images Attached Images  
    Last edited by Milk; Sep 29th, 2007 at 06:14 AM.

  6. #6
    Fanatic Member
    Join Date
    Jul 2007
    Location
    Essex, UK.
    Posts
    579

    Re: How to calculate usable screen area height

    Yes my friend, I am sure!

  7. #7
    Fanatic Member
    Join Date
    Jul 2007
    Location
    Essex, UK.
    Posts
    579

    Re: How to calculate usable screen area height

    Hmmm, how do I get it looking like yours??

  8. #8
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,448

    Re: How to calculate usable screen area height

    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
    Quote Originally Posted by Steve Grant
    Hmmm, how do I get it looking like yours??
    Not 100% sure, might be something to do with the size or that fact they are multiple images... the ones I posted are pings
    Attached Images Attached Images  
    Last edited by Milk; Sep 29th, 2007 at 08:34 AM.

  9. #9
    Fanatic Member
    Join Date
    Jul 2007
    Location
    Essex, UK.
    Posts
    579

    Re: How to calculate usable screen area height

    Hey Milk,

    I'm not sure what you mean when you state;

    I see that a normal form will take into account the menu, but not the toolbars wheras a MDI form will account for both
    If you look at my jpg's, they all show the same scaleheight (and height) for -

    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.

  10. #10
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,448

    Re: How to calculate usable screen area height

    I did (look at them), the form without a menu is shorter than the other two with a menu.

  11. #11
    Fanatic Member
    Join Date
    Jul 2007
    Location
    Essex, UK.
    Posts
    579

    Re: How to calculate usable screen area height

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

  12. #12
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    Re: How to calculate usable screen area height

    Quote Originally Posted by randem
    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.
    In form or screen co-ordinates?

    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.

  13. #13

    Thread Starter
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: How to calculate usable screen area height

    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.

  14. #14

    Thread Starter
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: [RESOLVED] How to calculate usable screen area height

    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.

  15. #15

    Thread Starter
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: [RESOLVED] How to calculate usable screen area height

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width