Results 1 to 9 of 9

Thread: [RESOLVED] Position my Form on the bottom right on load?

  1. #1

    Thread Starter
    Lively Member feneck's Avatar
    Join Date
    Mar 2007
    Location
    Australia, Queensland, Gympie
    Posts
    85

    Resolved [RESOLVED] Position my Form on the bottom right on load?

    What I want to do is have it so when, frmToast is loaded, the form is positioned to the users Bottom Right part of the screen.
    Basically where the MSN Toast (being the "person has signed in” thing) is…

    Your Help would be very much appreciated...

    REMEMBER TO RATE

  2. #2

  3. #3

    Thread Starter
    Lively Member feneck's Avatar
    Join Date
    Mar 2007
    Location
    Australia, Queensland, Gympie
    Posts
    85

    Re: Position my Form on the bottom right on load?

    This is a very good example. However Im looking for just a small bit of code that i can chuck into Form_Load()
    Can anyone help me?
    plz

    REMEMBER TO RATE

  4. #4
    Frenzied Member zynder's Avatar
    Join Date
    Nov 2006
    Location
    localhost
    Posts
    1,434

    Re: Position my Form on the bottom right on load?

    Try...

    vb Code:
    1. Private Sub Form_Load()    
    2.   'bottom right    
    3.   Me.Top = (Screen.Height) - (Me.Height)    
    4.   Me.Left = (Screen.Width) - (Me.Width)
    5. End Sub
    6.  
    7. Private Sub Form_Load()
    8.   'bottom left    
    9.   Me.Left = Screen.Width - Me.ScaleWidth    
    10.   Me.Top = Screen.Height - Me.ScaleHeight
    11. End Sub

    Hope it helps. Once again I have no VB installed here. Might encounter errors.

  5. #5

    Thread Starter
    Lively Member feneck's Avatar
    Join Date
    Mar 2007
    Location
    Australia, Queensland, Gympie
    Posts
    85

    Re: Position my Form on the bottom right on load?

    Thank you Very VERY VERY Much! hehe
    However, what do i do about the taskbar? it goes under that? now what do i do?

    REMEMBER TO RATE

  6. #6
    Addicted Member kewakl's Avatar
    Join Date
    Oct 2006
    Location
    between keyboard and chair
    Posts
    220

    Re: Position my Form on the bottom right on load?

    building on zynder's code, you can combine the Me.Top and Me.Left by
    using Me.Move

    object.Move left, top, width, height

    The Move method syntax has these parts:

    Part Description
    object Optional. An object expression that evaluates to an object in the Applies To list. If object is omitted, the form with the focus is assumed to be object.
    left Required. Single-precision value indicating the horizontal coordinate (x-axis) for the left edge of object.
    top Optional. Single-precision value indicating the vertical coordinate (y-axis) for the top edge of object.
    width Optional. Single-precision value indicating the new width of object.
    height Optional. Single-precision value indicating the new height of object.
    Do not use if shrinkwrap is broken or missing!
    I'm learning how to fish, too!

  7. #7

    Thread Starter
    Lively Member feneck's Avatar
    Join Date
    Mar 2007
    Location
    Australia, Queensland, Gympie
    Posts
    85

    Re: Position my Form on the bottom right on load?

    I found what i needed to find. Thank you all for you help.

    REMEMBER TO RATE

  8. #8
    Addicted Member kewakl's Avatar
    Join Date
    Oct 2006
    Location
    between keyboard and chair
    Posts
    220

    Re: [RESOLVED] Position my Form on the bottom right on load?

    EDIT: Late posting - great that you got it done!

    here is some code to CENTER the form in the screen, accounting for the taskbar, maybe you can modify it to work for bottom/right.
    from http://www.expressnewsindia.com/c4/ex1/C1028.html / www.freevbcode.com
    vb Code:
    1. Option Explicit
    2.  
    3. Private Declare Function GetSystemMetrics _
    4. Lib "user32" (ByVal nIndex As Long) As Long
    5.  
    6. Private Declare Function GetWindowLong Lib _
    7. "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, _
    8. ByVal nIndex As Long) As Long
    9.  
    10. Private Const SM_CXFULLSCREEN = 16
    11. Private Const SM_CYFULLSCREEN = 17
    12.  
    13. Public Function FormCenter(frmObj As Form) As Boolean
    14.  
    15. 'Centers form on screen, accounting for taskbars such as
    16. 'the windows taskbar, MS Office taskbar, etc.
    17. 'Pass the form you want to center as the frmObj
    18. 'parameter. Returns true if successful, false if not.
    19. 'Adapted from an example in VBPJ Tech Tips, 10th Edition
    20.  
    21. 'scale mode of form must be
    22. 'vbTwips, otherwise won't work
    23.  
    24. 'if you think that form's scale mode might be something else, incorporate
    25. 'the perpixelx and perpixels y functions for metrics other than twips:
    26. 'http://www.freevbcode.com/ShowCode.Asp?ID=102
    27.  
    28. Dim lLeft As Long
    29. Dim lTop As Long
    30.  
    31. On Error Resume Next
    32.  
    33. If frmObj.ScaleMode <> vbTwips Then Exit Function
    34.  
    35. lLeft = (Screen.TwipsPerPixelX * _
    36. GetSystemMetrics(SM_CXFULLSCREEN)) / 2
    37. lLeft = lLeft - (frmObj.Width / 2)
    38.  
    39. lTop = (Screen.TwipsPerPixelY * _
    40. GetSystemMetrics(SM_CYFULLSCREEN)) / 2
    41. lTop = lTop - (frmObj.Height / 2)
    42.  
    43. frmObj.Move lLeft, lTop
    44.  
    45. FormCenter = Err.Number = 0 And Err.LastDllError = 0
    46.  
    47. End Function
    Last edited by kewakl; Mar 31st, 2007 at 11:00 AM. Reason: Late
    Do not use if shrinkwrap is broken or missing!
    I'm learning how to fish, too!

  9. #9
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: [RESOLVED] Position my Form on the bottom right on load?

    Keep it simple:
    Code:
    Option Explicit
        Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" ( _
                        ByVal uAction As Long, _
                        ByVal uParam As Long, _
                        lpvParam As Any, _
                        ByVal fuWinIni As Long) As Long
    
        Private Const SPI_GETWORKAREA As Long = 48
    
        Private Type RECT
            lLeft As Long
            lTop As Long
            lRight As Long
            lBottom As Long
        End Type
    
    Private Sub Form_Load()
        Dim deskRECT As RECT
    
        Call SystemParametersInfo(SPI_GETWORKAREA, 0&, deskRECT, 0&)
    
        Me.Top = deskRECT.lBottom * Screen.TwipsPerPixelY - Me.Height
        Me.Left = deskRECT.lRight * Screen.TwipsPerPixelX - Me.Width
    End Sub

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