Results 1 to 6 of 6

Thread: [RESOLVED] Form Height & Top

  1. #1

    Thread Starter
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Resolved [RESOLVED] Form Height & Top

    How can i increase Form's Height and still keep it at it's original bottom position? Setting Height and Top works, but it doesn't satisfy me because you cannot do it at the same time, even with the Move method. When you use this in for example Timer loop, you get strange effects.

    Thanx!

    -gav

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Form Height & Top

    Unless you do something "interesting" I don't see why this simple thing won't work?
    Code:
    Option Explicit
    
    Private Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
    End Type
    
    Dim rc As RECT
    
    Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
    
    Private Sub Form_Load()
        Call GetWindowRect(Me.hwnd, rc)
    End Sub
    
    Private Sub Form_Resize()
    
        Me.Move Me.Left, rc.Bottom * Screen.TwipsPerPixelX - Me.Height
        If Me.Top < 0 Then Me.Top = 0
        
        Call GetWindowRect(Me.hwnd, rc)
    
    End Sub
    If you setting size via code you may need to use some flags.

  3. #3

    Thread Starter
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: Form Height & Top

    @RB: yes, i'm resizing through code - as in "Timer loop" from my opening post. Can't seem to see the solution in your answer.

  4. #4
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Form Height & Top

    I really don't see any complications. Here is a sample with the Timer:
    Code:
    Option Explicit
    
    Private Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
    End Type
    
    Dim rc As RECT
    
    Private Declare Function GetWindowRect Lib "user32" _
        (ByVal hwnd As Long, lpRect As RECT) As Long
    
    Private Sub Form_Load()
        Call GetWindowRect(Me.hwnd, rc)
        Timer1.Interval = 3000
        Timer1.Enabled = True
    End Sub
    
    Private Sub Form_Resize()
        Me.Move Me.Left, rc.Bottom * Screen.TwipsPerPixelX - Me.Height
        If Me.Top < 0 Then Me.Top = 0
    End Sub
    
    Private Sub Timer1_Timer()
        Call GetWindowRect(Me.hwnd, rc)
        Me.Height = Me.Height * 1.25
    End Sub

  5. #5

    Thread Starter
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: Form Height & Top

    Your solution works, but here's an even simpler one (withouth setting .Height directly)
    Code:
    Option Explicit
      Private m_lngNewHeight As Long
    
    Private Sub Form_Load()
      m_lngNewHeight = Me.Height
      
      Timer1.Enabled = False
      Timer1.Interval = 1
    End Sub
    
    Private Sub Form_Resize()
      Me.Move Me.Left, Me.Top - (m_lngNewHeight - Me.Height), Me.Width, m_lngNewHeight
    End Sub
    
    Private Sub Command1_Click()
      Timer1.Enabled = True
    End Sub
    
    Private Sub Timer1_Timer()
      m_lngNewHeight = Me.Height + 20
      
      Form_Resize
    End Sub
    I guess i'll have to play around a bit before asking for help next time

    Thanx anyway!

    -gav

  6. #6

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