|
-
Dec 4th, 2011, 12:53 PM
#1
Thread Starter
Addicted Member
[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?
-
Dec 4th, 2011, 01:42 PM
#2
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.
-
Dec 4th, 2011, 02:30 PM
#3
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
-
Dec 5th, 2011, 03:53 AM
#4
Thread Starter
Addicted Member
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!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|