CT SizeManager ActiveX Library allows you to restrict the minimum and maximum size of a specified window and automatically resizes and moves selected controls from Visual Basic applications. This library file is specifically designed for Visual Basic, but may work in any environment that supports ActiveX technology.
Classes |
|
---|---|
TrackSizeObject Class |
|||
---|---|---|---|
Properties |
Methods |
Events |
|
|
|||
|
|
This class allows you to restrict the minimum and maximum size of a window. Properties and methods of this class can be invoked after creating or referencing an object. You are free to create as many objects as you wish by declaring them As New.
Note:
Always save your work
before testing your application.
Release the captured
windows before debugging your application.
If you halt the
program instead of unloading the objects referencing this class, it
will crash and so will the VB IDE.
As a general rule, define your own conditional compiler constant and set its value to -1 (True) only when your program is free of errors (see the example below).
#Const CT_TRACKSIZERUNTIME =
-1 '0 = debug mode
...
#If CT_TRACKSIZERUNTIME
Then
ctTrackSizeManager.Capture hWnd
#End If
...
The MinWidth and MinHeight properties return/set the minimum width and height of the window to be captured, given in twips.
MinWidth As Single
MinHeight As Single
Set these properties to 0 whenever you want them to be ignored.
Dim ctTrackSizeManager As New TrackSizeObject
'limits the minimum size of
the form to half of its dimensions
ctTrackSizeManager.MinWidth =
0.5 * Form1.Width
ctTrackSizeManager.MinHeight = 0.5 *
Form1.Height
Set ctTrackSizeManager = Nothing
The MaxWidth and MaxHeight properties return/set the maximum width and height of the window to be captured, given in twips.
MaxWidth As Single
MaxHeight As Single
Set these properties to 0 whenever you want them to be ignored.
Dim ctTrackSizeManager As New TrackSizeObject
'limits the maximum width of
the form to double of its width
ctTrackSizeManager.MaxWidth = 2 *
Form1.Width
'suppose you don't care of
the maximum height of the form
ctTrackSizeManager.MaxHeight = 0
Set ctTrackSizeManager = Nothing
The Capture method establishes a hook to capture messages to the specified window.
Capture(ByVal hWnd As Long)
hWnd |
The handle to the window. |
None
The Microsoft Windows operating environment identifies each form and control in an application by assigning it a handle (hWnd). The hWnd value is used with Windows API calls. Many Windows operating environment functions require the hWnd of a specific window as an argument. Because the value of this argument can change while a program is running, never store the hWnd value in a variable.
Dim ctTrackSizeManager As New TrackSizeObject
'limits the minimum size of
the form to half of its dimensions
ctTrackSizeManager.MinWidth =
0.5 * Form1.Width
ctTrackSizeManager.MinHeight = 0.5 *
Form1.Height
'limits the maximum size of
the form to double of its dimensions
ctTrackSizeManager.MaxWidth =
2 * Form1.Width
ctTrackSizeManager.MaxHeight = 2 * Form1.Height
ctTrackSizeManager.Capture Form1.hWnd
Set ctTrackSizeManager = Nothing
ResizableControls Class |
|||
---|---|---|---|
Properties |
Methods |
Events |
|
|
|||
|
This class automatically resizes and moves selected controls as specified when the reference object is resized. Properties and methods of this class can be invoked after creating or referencing an object. You are free to create as many objects as you wish by declaring them As New.
The Reference property returns/sets the object whose size is used as reference.
Reference As Object
When the Reference property is initialized, the library records its size and uses that size as reference for resizing until you change the reference object. The reference object may be any object expression that evaluates to an object (for instance, a Form, a PictureBox or a TextBox control).
Dim ctResizableControls As New ResizableControls
Set ctResizableControls.Reference = Form1
Set ctResizableControls = Nothing
The RefWidth and RefHeight properties return/set the width and height, given in twips, of the object whose size is used as reference.
RefWidth As Single
RefHeight As Single
Use these properties only when referencing the object (through the Reference property) conducts to undesirable results.
Dim ctResizableControls As New ResizableControls
ctResizableControls.RefWidth
= Form1.Width
ctResizableControls.RefHeight = Form1.Height
Set ctResizableControls = Nothing
The Add method adds controls to the resizable collection.
Add(Control As Object, Optional ByVal lRatio As Single = 0, Optional ByVal tRatio As Single = 0, Optional ByVal wRatio As Single = 0, Optional ByVal hRatio As Single = 0)
Control |
The control to be resized. |
lRatio |
Horizontal movement of the Control. |
tRatio |
Vertical movement of the Control. |
wRatio |
Horizontal sizing of the Control. |
hRatio |
Vertical sizing of the Control. |
None
When adding the control, its position and size are automatically recorded as a base for resizing. The lRatio, tRatio, wRatio and hRatio parameters should be assigned a value between 0 and 1.
Follow the expressions below to determine the correct values:
lRatio, tRatio
newctlLeft
= (lRatio * (oldrefWidth - newrefWidth)) +
oldctlLeft
newctlTop = (tRatio *
(oldrefHeight - newrefHeight)) + oldctlTop
0
= no movement; 0.5 = 50% movement; 1 = 100% movement.
wRatio, hRatio
newctlWidth
= (wRatio * (oldrefWidth - newrefWidth)) +
oldctlWidth
newctlHeight = (hRatio
* (oldrefHeight - newrefHeight)) + oldctlHeight
0
= no sizing; 0.5 = 50% sizing; 1 = 100% sizing.
Dim ctResizableControls As New ResizableControls
Set ctResizableControls.Reference = Form1
ctResizableControls.Add
Label1, 1, 1, 0, 0
ctResizableControls.Add Text1, 1, 1, 1, 0
Set ctResizableControls = Nothing
The Resize method moves and resizes controls as specified when the reference object is resized.
Resize(Optional ByVal ResizeNow As Boolean = True, Optional ByVal wSizeNow As Single = -1, Optional ByVal hSizeNow As Single = -1)
ResizeNow |
When False, no control will be moved or resized. |
wSizeNow |
The width used as reference, given in twips. |
hSizeNow |
The height used as reference, given in twips. |
None
Set the reference object or dimensions, then add controls to the resizable collection before calling this method. The last two parameters of this method are usually used in conjunction with the RefWidth and RefHeight properties.
Private ctResizableControls As ResizableControls
Private Sub
Form_Load()
Set ctResizableControls = New
ResizableControls
Set ctResizableControls.Reference = Me
ctResizableControls.Add
Label1, 1, 1, 0, 0
ctResizableControls.Add Text1, 1,
1, 1, 0
End Sub
Private Sub
Form_Resize()
ctResizableControls.Resize
End Sub
Private Sub
Form_Unload(Cancel As Integer)
Set ctResizableControls
= Nothing
End Sub
Windows 95/98, NT, 2000
Visual Basic 6.0 RunTime
files
You can get Visual Basic 6.0 RunTime files from
Simtel.Net
http://www.simtel.net/pub/simtelnet/win95/dll.html
Reference for further information
http://softrunner.homestead.com
Comments, suggestions or bugs reports
cbotez@homestead.com
CT SizeManager ActiveX Library
Copyright ©
2000, Cezar Botez
All rights reserved