Results 1 to 11 of 11
  1. #1
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10

    Unanswered: Form height property

    Hey peeps; hope this is an easy one (and I'm not just being a fool)!

    I want to know how to find the form HEIGHT property (if it exists).
    Width is easy
    Code:
    Debug.Print Me.Width
    But what about a forms' height?
    George
    Home | Blog

  2. #2
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    This was fun researching! You have to access each part of the form separately!!!

    Debug.Print Me.FormHeader.Height
    Debug.Print Me.Detail.Height
    Debug.Print Me.FormFooter.Height
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  3. #3
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Thank you Missinglinq - you're a star!
    I never even thought about doing it that way
    I guess width is different because it really is a shared property.
    I guess I could (pretty much) say
    Code:
    FormHeight = Me.FormHeader.Height + Me.Detail.Height + Me.FormFooter.Height
    George
    Home | Blog

  4. #4
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Ooh whilst I'm still here - how about the current co-ordinates of a form?
    Controls are "easy" enough
    Code:
    Debug.Print Me.MyControl.Left
    Debug.Print Me.MyControl.Top
    Any ideas?
    George
    Home | Blog

  5. #5
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    441
    Be aware (if you're intending to copy/paste the code), that the names of the sections are changeable (other tab, name property), and also localized. For instance in the local version where I live, the name of the Detail section, is Detalj. For safety, mayhaps

    Me.Section(acHeader).Height
    Me.Section(acDetail).Height
    Me.Section(acFooter).Height

    For form position, check out http://www.pacificdb.com.au/MVP/Code/FormPos.htm
    Roy-Vidar

  6. #6
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Thanks for the link - lovely bit of code - but I'm not getting the desired results...
    Code:
    Private Type RECT
        left As Long
        top As Long
        right As Long
        bottom As Long
    End Type
    
    Private Declare Function GetWindowRect Lib "user32" _
        (ByVal hwnd As Long, lpRect As RECT) As Long
    
    Private Sub cmdShow_Click()
        Dim FormDims As RECT
        Dim x, y As Integer
    
        If GetWindowRect(Me.hwnd, FormDims) Then
                x = FormDims.left
                y = FormDims.top
                'FormDims.right
                'FormDims.bottom
        End If
    DoCmd.MoveSize x - 1, y - 1
    
    End Sub
    Basically the form should move one pixel towards the top left of the screen every time you click cmdShow but if you give it a go - it doesn't!
    (please note that I know the action of the button is silly - this is just my way of testing that I get the value I need )
    George
    Home | Blog

  7. #7
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Ok I've found some more information:
    FormDims.left returns the coordinate of the left side of the window.
    FormDims.top returns the coordinate of the top of the window.
    FormDims.right returns the distance in pixels from the left side to the right side of the window
    FormDims.bottom returns the distance in pixels from the top to the bottom of the window

    So I assume this means that the co-ordinate values are not pixels - which explains why I'm not getting the desired result.
    Can anyone tell me the relationship between the two units? Constant ratio perhaps (I hope!)?
    George
    Home | Blog

  8. #8
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    441
    Ah, so you wanted positioning too

    http://support.microsoft.com/kb/210141
    Roy-Vidar

  9. #9
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Ahh a lovely link - but I fear it is far to complex for what I want... (I only understand about 50% of the code).
    This is all in follow up to a recent thread with Poots about GUI's - I was playing with the idea of how to create a splash form that - well - take a look at the example I've uploaded.

    The problem I currently have is no matter where the form is on the page it "jumps" before it "shrinks"
    Ideally I simply want to set my x and y values to the current position and bob's your uncle - problem solved.

    Any question etc please feel free
    Attached Files Attached Files
    George
    Home | Blog

  10. #10
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    441
    The calculation seems to be slightly off, at least on my setup.

    Try
    Code:
    Sub TestFormMoving(ByVal v_strForm As String)
        
        Dim frm As Form
        Dim x As Long, x2 As Long, y As Long, y2 As Long
        
        ' I'm using a "good old" IsLoaded function ;)
        If Not IsLoaded(v_strForm) Then
            MsgBox "isn't open..."
            Exit Sub
        End If
        Set frm = Forms(v_strForm)
        GetFormDimensions frm, x, x2, y, y2
        
        DoCmd.MoveSize x - 25, x2 - 25
    End Sub
    Roy-Vidar

  11. #11
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10

    Full solution

    C'etait perfect!
    Here is my full solution
    Place the following code into a module - reference http://support.microsoft.com/kb/210141
    Code:
    Option Explicit
    
    Type RECT_Type
       left As Long
       top As Long
       right As Long
       bottom As Long
    End Type
    
    Declare Function apiGetWindowRect Lib "user32" Alias _
       "GetWindowRect" (ByVal hWnd As Long, lpRect As RECT_Type) As Long
    Declare Function apiGetDC Lib "user32" Alias "GetDC" _
       (ByVal hWnd As Long) As Long
    Declare Function apiReleaseDC Lib "user32" Alias "ReleaseDC" (ByVal _
       hWnd As Long, ByVal hDC As Long) As Long
    Declare Function apiGetDeviceCaps Lib "gdi32" Alias "GetDeviceCaps" _
       (ByVal hDC As Long, ByVal nIndex As Long) As Long
    Declare Function apiGetActiveWindow Lib "user32" Alias _
       "GetActiveWindow" () As Long
    Declare Function apiGetParent Lib "user32" Alias "GetParent" (ByVal _
       hWnd As Long) As Long
    Declare Function apiGetClassName Lib "user32" Alias "GetClassNameA" _
       (ByVal hWnd As Long, ByVal lpClassName As String, ByVal _
       nMaxCount As Long) As Long
    
    Global Const TWIPSPERINCH = 1440
    
    Sub GetFormDimensions(F As Form, FLeft As Long, FTop As Long, _
       FWidth As Long, FHeight As Long)
       '*************************************************************
       ' PURPOSE: Returns the left, top, width, and height
       '          measurements of a form window in tdwips.
       ' ARGUMENTS:
       '    F: The form object whose measurements are to be determined.
       '    FLeft, FTop, FWidth, FHeight: Measurement variables
       '    that will return the dimensions of form F "by reference."
       ' NOTE: The FWidth and FHeight values will be equivalent to
       '    those provided by the form WindowWidth and WindowHeight
       '    properties.
       '*************************************************************
       Dim FormRect As RECT_Type
       Dim MDIClient As RECT_Type
       Dim MDIClientLeft As Long
       Dim MDIClientTop  As Long
       
       ' Get the screen coordinates and window size of the form.
       ' The screen coordinates are returned in pixels measured
       ' from the upper-left corner of the screen.
       apiGetWindowRect F.hWnd, FormRect
       FLeft = FormRect.left
       FTop = FormRect.top
       FWidth = FormRect.right - FormRect.left
       FHeight = FormRect.bottom - FormRect.top
       
       ' Convert the measurements from pixels to twips.
       ConvertPIXELSToTWIPS FLeft, FTop
       ConvertPIXELSToTWIPS FWidth, FHeight
       
       ' If the form is not a pop-up form, adjust the screen
       ' coordinates to measure from the top of the Microsoft
       ' Access MDIClient window. Position 0,0 for a pop-up form
       ' is the upper-left corner of the screen, whereas position
       ' 0,0 for a normal window is the upper-left corner of the
       ' Microsoft Access client window below the menu bar.
       If GetWindowClass(F.hWnd) <> "OFormPopup" Then
          ' Get the screen coordinates and window size of the
          ' MDIClient window.
          apiGetWindowRect apiGetParent(F.hWnd), MDIClient
          MDIClientLeft = MDIClient.left
          MDIClientTop = MDIClient.top
          ConvertPIXELSToTWIPS MDIClientLeft, MDIClientTop
          
          ' Adjust the form dimensions from the MDIClient
          ' measurements.
          FLeft = FLeft - MDIClientLeft
          FTop = FTop - MDIClientTop
       End If
    End Sub
    
    Sub ConvertPIXELSToTWIPS(x As Long, y As Long)
    
       '*************************************************************
       ' PURPOSE: Converts the two pixel measurements passed as
       '          arguments to twips.
       ' ARGUMENTS:
       '    X, Y: Measurement variables in pixels. These will be
       '          converted to twips and returned through the same
       '          variables "by reference."
       '*************************************************************
       Dim hDC As Long, hWnd As Long, RetVal As Long
       Dim XPIXELSPERINCH, YPIXELSPERINCH
       Const LOGPIXELSX = 88
       Const LOGPIXELSY = 90
       
       ' Retrieve the current number of pixels per inch, which is
       ' resolution-dependent.
       hDC = apiGetDC(0)
       XPIXELSPERINCH = apiGetDeviceCaps(hDC, LOGPIXELSX)
       YPIXELSPERINCH = apiGetDeviceCaps(hDC, LOGPIXELSY)
       RetVal = apiReleaseDC(0, hDC)
       
       ' Compute and return the measurements in twips.
       x = (x / XPIXELSPERINCH) * TWIPSPERINCH
       y = (y / YPIXELSPERINCH) * TWIPSPERINCH
    
    End Sub
    
    Function GetWindowClass(hWnd As Long) As String
    
       '*************************************************************
       ' PURPOSE: Retrieve the class of the passed window handle.
       ' ARGUMENTS:
       '    hWnd: The window handle whose class is to be retrieved.
       ' RETURN:
       '    The window class name.
       '*************************************************************
       Dim Buff As String
       Dim BuffSize As Integer
       Buff = String$(255, " ")
       BuffSize = apiGetClassName(hWnd, Buff, 255)
       GetWindowClass = left$(Buff, BuffSize)
    
    End Function
    Then the following on the splash form
    Code:
    Option Compare Database
    Option Explicit
    
    Dim i, w, h, x, y, p As Integer
    
    Dim FormDims As RECT
    
    Private Type RECT
        left As Long
        top As Long
        right As Long
        bottom As Long
    End Type
    
    Private Declare Function GetWindowRect Lib "user32" _
        (ByVal hWnd As Long, lpRect As RECT) As Long
    
    Private Sub Form_Load()
        
        If GetWindowRect(Me.hWnd, FormDims) Then
            x = FormDims.right
            y = FormDims.top
        End If
        
        Me.TimerInterval = 2000
        i = 1
        w = Me.Width
        h = Me.Detail.Height
        p = 25
    
    End Sub
    
    Private Sub Form_Timer()
    
        Me.TimerInterval = 1
        
        MoveForm (Me.Name)
        i = i + 1
        
        If i = p + 1 Then
            DoCmd.Close acForm, "Splash"
        End If
    
    End Sub
    
    Function MoveForm(ByVal v_strForm As String)
    
    Dim frm As Form
    Dim x As Long, x2 As Long, y As Long, y2 As Long
    
        Set frm = Forms(v_strForm)
        GetFormDimensions frm, x, x2, y, y2
        
        DoCmd.MoveSize x * ((p - i) / p), x2 * ((p - i) / p), w * ((p - i) / p), h * ((p - i) / p)
    
    End Function
    Thanks for all your help guys and gals!
    George
    Home | Blog

Posting Permissions

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