Results 1 to 11 of 11

Thread: Resize Form

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2002
    Location
    Rome, Italy
    Posts
    150

    Resize Form

    I have form that I didnt care how big it gets but want to limit how small resize can be.

    How is this acomplish?
    Catholics Do It With Beads

  2. #2
    Software Eng. Megatron's Avatar
    Join Date
    Mar 1999
    Location
    Canada
    Posts
    11,286
    You'd have to subclass, and catch the WM_SIZING message. Then just do something like:

    If myform.width < x and myform.height < y then
    myform.width=x
    myform.height=y
    exit function
    end if-

  3. #3
    Lively Member
    Join Date
    Sep 2002
    Location
    Basingstoke
    Posts
    86

    Try this...

    Private Sub Form_Resize()
    If Me.Height < 5000 Then
    Me.Height = 5000
    End If
    If Me.Width < 5000 Then
    Me.Width = 5000
    End If
    End Sub

    messy but works

  4. #4
    Software Eng. Megatron's Avatar
    Join Date
    Mar 1999
    Location
    Canada
    Posts
    11,286
    Actually this would work too.
    Code:
    Private Sub Form_Resize()
    
    If Me.Width < 2000 Then Me.Width = 2000
    If Me.Height < 2000 Then Me.Height = 2000
    
    End Sub

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    May 2002
    Location
    Rome, Italy
    Posts
    150
    Mr. Megatron that you. I am reading many of your writings and you are very good.

    How is this subclassing you speak of done? I would like to learn?
    Catholics Do It With Beads

  6. #6
    Software Eng. Megatron's Avatar
    Join Date
    Mar 1999
    Location
    Canada
    Posts
    11,286
    It's done via SetWindowLong. I don't have my ApiViewer on this machine, but I'll try to find an example on the net for you.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    May 2002
    Location
    Rome, Italy
    Posts
    150
    Many thank yous Mr. Megatron
    Catholics Do It With Beads

  8. #8
    Software Eng. Megatron's Avatar
    Join Date
    Mar 1999
    Location
    Canada
    Posts
    11,286
    This link shows a basic example of subclassing.

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    May 2002
    Location
    Rome, Italy
    Posts
    150
    THank you Mr. Megatron, but how do I sue this to stop resize from being to small?
    Catholics Do It With Beads

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    May 2002
    Location
    Rome, Italy
    Posts
    150
    Is there noone to help?
    Catholics Do It With Beads

  11. #11
    Frenzied Member MerrionComputin's Avatar
    Join Date
    Apr 2001
    Location
    Dublin, Ireland
    Posts
    1,616

    Controling form resizing *FAQ*

    Using the EventVB.dll it can be done thus:

    VB Code:
    1. Option Explicit
    2.  
    3. Dim WithEvents vbLink As EventVB.APIFunctions
    4. Dim WithEvents vbWnd As EventVB.ApiWindow
    5.  
    6. Const WNDMINWIDTH = 200
    7. Const WNDMINHEIGHT = 200
    8.  
    9. Const WNDMAXWIDTH = 400
    10. Const WNDMAXHEIGHT = 400
    11.  
    12.  
    13. Private Sub Form_Load()
    14.  
    15. Set vbLink = New APIFunctions
    16.  
    17. Set vbWnd = New ApiWindow
    18. vbWnd.hWnd = Me.hWnd
    19.  
    20. vbLink.SubclassedWindows.Add vbWnd
    21.  
    22. End Sub
    23.  
    24. Private Sub vbLink_ApiError(ByVal Number As Long, ByVal Source As String, ByVal Description As String)
    25.  
    26. Debug.Print Description & " - " & Source
    27.  
    28. End Sub
    29.  
    30.  
    31. Private Sub vbWnd_MinMaxSize(MaxHeight As Long, MaxWidth As Long, MaxPositionTop As Long, MaxPositionLeft As Long, MinTrackWidth As Long, MinTrackheight As Long, MaxTrackWidth As Long, MaxTrackHeight As Long)
    32.  
    33. MaxHeight = WNDMAXHEIGHT
    34. MaxWidth = WNDMAXWIDTH
    35.  
    36. End Sub
    37.  
    38. Private Sub vbWnd_Sizing(ByVal SizeEdges As EventVB.WindowSizingEdges, DragRectangle As EventVB.APIRect)
    39.  
    40. With DragRectangle
    41.     If .Bottom - .Top < WNDMINHEIGHT Then
    42.         If SizeEdges = WMSZ_BOTTOM Or SizeEdges = WMSZ_BOTTOMLEFT Or SizeEdges = WMSZ_BOTTOMRIGHT Then
    43.             .Bottom = .Top + WNDMINHEIGHT
    44.         Else
    45.             .Top = .Bottom - WNDMINHEIGHT
    46.         End If
    47.     ElseIf .Bottom - .Top > WNDMAXHEIGHT Then
    48.         If SizeEdges = WMSZ_BOTTOM Or SizeEdges = WMSZ_BOTTOMLEFT Or SizeEdges = WMSZ_BOTTOMRIGHT Then
    49.             .Bottom = .Top + WNDMAXHEIGHT
    50.         Else
    51.             .Top = .Bottom - WNDMAXHEIGHT
    52.         End If
    53.     End If
    54.    
    55.     If .Right - .Left < WNDMINWIDTH Then
    56.         If SizeEdges = WMSZ_RIGHT Or SizeEdges = WMSZ_BOTTOMRIGHT Or SizeEdges = WMSZ_TOPRIGHT Then
    57.             .Right = .Left + WNDMINWIDTH
    58.         Else
    59.             .Left = .Right - WNDMINWIDTH
    60.         End If
    61.     ElseIf .Right - .Left > WNDMAXWIDTH Then
    62.         If SizeEdges = WMSZ_RIGHT Or SizeEdges = WMSZ_BOTTOMRIGHT Or SizeEdges = WMSZ_TOPRIGHT Then
    63.             .Right = .Left + WNDMAXWIDTH
    64.         Else
    65.             .Left = .Right - WNDMAXWIDTH
    66.         End If
    67.     End If
    68.    
    69. End With
    70.  
    71. End Sub

    Hope this helps,
    Duncan
    ----8<---------------------------------------
    NEW - The .NET printer queue monitor component
    ----8<---------------------------------------
    Now with Examples of use

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