Results 1 to 5 of 5

Thread: Position is Everything

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2000
    Posts
    367
    Did the subject get ya to look?

    I have seen some references but just cant find any right now. When positioning my form I want it to be on the lowest possible location, but if any taskbar/appbars are there, my form would of course need to be on higher up on the screen.

    Here is the code I have right now

    Code:
    Public Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
    Public Const SM_CXSCREEN = 0
    Public Const SM_CYSCREEN = 1
    
    
    
    Public Sub CenterForm(formName As Form)
    
        
        ' Position a form on the screen
        'formName.Top = (Screen.Height - formName.Height)
        MsgBox Screen.Height & vbCrLf & GetSystemMetrics(SM_CYSCREEN) * Screen.TwipsPerPixelY
        formName.Top = ((GetSystemMetrics(SM_CYSCREEN) * Screen.TwipsPerPixelY) - formName.Height)
        formName.Left = 0
        'formName.Width = Screen.Width
        formName.Width = (GetSystemMetrics(SM_CXSCREEN) * Screen.TwipsPerPixelX)
    
    End Sub
    But it doesnt account for the taskbar, it puts the form on lowest location possible and since the taskbar is there it goes over my form, ugg, which isnt too cool.

    Thanks

  2. #2
    Lively Member benski's Avatar
    Join Date
    Sep 1999
    Location
    UK
    Posts
    126

    Lightbulb

    If you're willing to add the SysInfo control to your project, you can do it the easy way:

    This example tests the size of the active form after a change in screen resolution and adjusts the size of the form if it exceeds the visible screen area. To run this example, put a SysInfo control on a form. Paste this code into the DisplayChanged event of the SysInfo control. Run the example, then change the screen resolution.

    Code:
    Private Sub SysInfo1_DisplayChanged()
        If Screen.ActiveForm.Width > SysInfo1.WorkAreaWidth Then
            Screen.ActiveForm.Left = SysInfo1.WorkAreaLeft
            Screen.ActiveForm.Width = SysInfo1.WorkAreaWidth
        End If
        If Screen.ActiveForm.Height > SysInfo1.WorkAreaHeight Then
            Screen.ActiveForm.Top = SysInfo1.WorkAreaTop
            Screen.ActiveForm.Height = SysInfo1.WorkAreaHeight
        End If
    End Sub
    If you still want api, erm, I'll have to find what api calls SysInfo is using to get it's WorkArea properties.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    May 2000
    Posts
    367
    I think I may have to use SHAppBarMessage, and then query for position, but the form I have is not really an appbar, I just want it to have the lowest spot availabe on the screen but higher then any tool/task bar.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    May 2000
    Posts
    367

    Question

    How do I get the available screen space which takes into effect the task/app bars?

    Anyone?

  5. #5
    Lively Member benski's Avatar
    Join Date
    Sep 1999
    Location
    UK
    Posts
    126

    Question

    What is wrong with including the SysInfo control - sure it's a bit big to do just that job, but if it does the job then I'd go with it, rather than worrying about low-level api stuff that we're not sure about?

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