Results 1 to 7 of 7

Thread: Detect resize Top/Bottom vs Left/Right?

  1. #1

    Thread Starter
    Member Mugsy323's Avatar
    Join Date
    Oct 2014
    Posts
    45

    Question Detect resize Top/Bottom vs Left/Right?

    I have the following code in my Form1.Resize event:

    Code:
    Private Sub frmMain_Resize(sender As Object, e As EventArgs) Handles Me.Resize
            dblRatio = Screen.PrimaryScreen.Bounds.Height / Screen.PrimaryScreen.Bounds.Width
            Me.Height = Me.Width * dblRatio
    End Sub
    This resizes the form proportionally if dragged from the sides or corners, but not Top/Bottom b/c there's no way to discern which side of the form is grabbed (ie: I can't change "Me.Width" based on height right after changing "Me.Height" based on width.)

    I don't want the form to resize proportionally if grabbed from the Top/Bottom. Only when resized from the sides.

    Is there a Method that can detect which side of the form is being dragged?

    TIA

  2. #2
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,607

    Re: Detect resize Top/Bottom vs Left/Right?

    Have you looked at using the anchor property? That may do what you want.
    Please remember next time...elections matter!

  3. #3
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,607

    Re: Detect resize Top/Bottom vs Left/Right?

    Have you looked at using the anchor property on the controls? That may do what you want.
    Please remember next time...elections matter!

  4. #4

    Thread Starter
    Member Mugsy323's Avatar
    Join Date
    Oct 2014
    Posts
    45

    Re: Detect resize Top/Bottom vs Left/Right?

    Quote Originally Posted by TysonLPrice View Post
    Have you looked at using the anchor property? That may do what you want.
    Yeah, that was the first thing I tried. But I couldn't figure out how to check the value.

  5. #5
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Pointless Forest 38.517,-92.023
    Posts
    9,395

    Re: Detect resize Top/Bottom vs Left/Right?

    It will be something like this,

    Code:
        Private mySizeBeg As Size 'size at ResizeBegin 
        Private mySizeIP As Size 'size during Resize
    
        Private Sub Form1_ResizeBegin(sender As Object, e As EventArgs) Handles Me.ResizeBegin
            mySizeBeg = Me.Size 'set begin size
        End Sub
    
        Private Sub Form1_Resize(sender As Object, e As EventArgs) Handles Me.Resize
            If mySizeIP.Width = 0 AndAlso mySizeIP.Height = 0 Then
                'first time
                Debug.WriteLine("1")
                mySizeIP = Me.Size
                Exit Sub
            End If
            mySizeIP = Me.Size
            If mySizeIP.Width = mySizeBeg.Width AndAlso mySizeIP.Height <> mySizeBeg.Height Then
                Debug.WriteLine("height changing")
            ElseIf mySizeIP.Width <> mySizeBeg.Width AndAlso mySizeIP.Height = mySizeBeg.Height Then
                Debug.WriteLine("width changing")
            ElseIf mySizeIP.Width = mySizeBeg.Width AndAlso mySizeIP.Height = mySizeBeg.Height Then
                Debug.WriteLine("same")
            Else
                ' both changing
                mySizeBeg = New Size(0, 0) 'kill begin size
                Dim dblRatio As Double = Screen.PrimaryScreen.Bounds.Height / Screen.PrimaryScreen.Bounds.Width
                Me.Height = CInt(Me.Width * dblRatio)
            End If
        End Sub
    
        Private Sub Form1_ResizeEnd(sender As Object, e As EventArgs) Handles Me.ResizeEnd
            mySizeIP = New Size(0, 0) 'reset in progress
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  6. #6
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,179

    Re: Detect resize Top/Bottom vs Left/Right?

    An alternative that also works. It's a little bit more concise even discounting the Debug lines.
    Code:
        Private formAspect As Double
        Private formWidth, formHeight As Integer
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
            formAspect = Screen.PrimaryScreen.Bounds.Height /Screen.PrimaryScreen.Bounds.Width
            formWidth = Me.Width
            Me.Height = CInt(Me.Width * formAspect)
            formHeight = Me.Height
        End Sub
    
        Private Sub Form1_Resize(sender As Object, e As EventArgs) Handles Me.Resize
            If Me.Width <> formWidth Then 'side or corner is dragged
                Me.Height = CInt(formAspect * Me.Width) 'resize proportionally
            ElseIf Me.Height <> formHeight Then 'bottom only is dragged
                formHeight = Me.Height 'height only is changed
                formAspect = formHeight / formWidth 'note: aspect is also modified
            End If
            formWidth = Me.Width
        End Sub

  7. #7

    Thread Starter
    Member Mugsy323's Avatar
    Join Date
    Oct 2014
    Posts
    45

    Re: Detect resize Top/Bottom vs Left/Right?

    This looks great. I'll try it out now. Thx!

    FOLLOW-UP: Awesome. Works great. Big thanks.
    Last edited by Mugsy323; Oct 27th, 2021 at 01:37 PM.

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