Results 1 to 4 of 4

Thread: [RESOLVED] Form Minimum Size

  1. #1

    Thread Starter
    Addicted Member cheesebrother's Avatar
    Join Date
    Jul 2011
    Posts
    153

    Resolved [RESOLVED] Form Minimum Size

    I'm trying to limit the size of the form. Basically, i have a form which i don't want to be smaller than 5000 by 3000 twips. So the basic thing which you can think of in a millisecond is this:

    Code:
    Private Sub Form_Resize()
      If Me.Width < 5000 Then Me.Width = 5000
      If Me.Height < 3000 Then Me.Height = 3000
    End Sub
    But if you try that it looks REALLY nasty when you go smaller as it flashes like crazy. How can i accomplish the same thing except doing it much cleaner like lots and lots of other programs which have a minimum size?
    Hooked for good.

  2. #2
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Form Minimum Size

    Normally I don't have a lot of use for PSC, but here is an article that lays out the issues and your options from simple to complex fairly well:

    http://www.planetsourcecode.com/vb/s...68026&lngWId=1

    The easiest uses a Timer control to assist with resizing.

  3. #3
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Form Minimum Size

    Here is a boiled down and cleaned up example of his approach you can test quickly by creating a new project with one Form and adding one Timer to it:
    Code:
    Option Explicit
    'Relies on a Timer named tmrResizeHelp.
    
    Private Const FORM_MINWIDTH = 3600
    Private Const FORM_MINHEIGHT = 3300
    
    Private Declare Function GetKeyState Lib "user32" ( _
        ByVal nVirtKey As KeyCodeConstants) As Integer
    
    Private Sub Form_Load()
     With tmrResizeHelp
        .Enabled = False
        .Interval = 100
     End With
    End Sub
    
    Private Sub Form_Resize()
        If WindowState <> vbMinimized Then
            'Min size control logic:
            If Width < FORM_MINWIDTH Or Height < FORM_MINHEIGHT Then
                Refresh
                tmrResizeHelp.Enabled = True
                Exit Sub
            End If
            'Your control resizing and moving goes here:
            '...
        End If
    End Sub
    
    Private Sub tmrResizeHelp_Timer()
        If GetKeyState(vbKeyLButton) < 0 Then Exit Sub
        tmrResizeHelp.Enabled = False
        If WindowState = vbMinimized Then Exit Sub
        If Width < FORM_MINWIDTH Then Width = FORM_MINWIDTH
        If Height < FORM_MINHEIGHT Then Height = FORM_MINHEIGHT
    End Sub
    Test it to be sure the results are something that works for you.
    Last edited by dilettante; Dec 4th, 2011 at 03:11 PM. Reason: deleted yet another line of code I don't think is needed

  4. #4

    Thread Starter
    Addicted Member cheesebrother's Avatar
    Join Date
    Jul 2011
    Posts
    153

    Re: Form Minimum Size

    Thanks for the reply. That works pretty well with a timer, maybe i'll do that. I went to the website and kinda got lost in the more complicated code... Anyway, there really is no way of making it completely stop when it's too small? While toying around with VB2010 i noticed that minimum form size was a property so i was hoping that the same could be done with apis or something. The timer thing will do though so my question has been answered. Thanks a lot for your help!
    Hooked for good.

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