|
I've got a problem creating a class. Could someone take a quick look and see what I'm doing wrong? The code works great (to resize a form to match the size of the forms' .picture) when it is in a BAS module, but when I put it in a class module, if hangs on f = SizeTheForm. Says "Invalid use of property." The problem is somehow passing the form to the class. Here it is:
In the projects only form (form1):
Private TheFile As String
Option Explicit
Private Sub Form_Load()
Dim Blob As New FormSizer
TheFile = "C:\Test JPEG's\A cute picture.jpg"
Form1.Picture = LoadPicture(TheFile)
Blob.SizeTheForm = Me
Set Blob = Nothing
End Sub
Then in the class module:
Option Explicit
Private w As Long
Private h As Long
Private f As Form
Property Let SizeTheForm(ByRef f As Form)
f = SizeTheForm 'This is where it hangs - "Invalid use of property"
w = f.Picture.Width 'Gets the picture width in HiMetric units
h = f.Picture.Height 'Gets the picture height in HiMetric units
Select Case f.ScaleMode
Case 0 'the form to be sized is in ScaleMode 0, User
f.ScaleMode = 1 'Temporarily resets f.ScaleMode to Twips for manipulation...
w = f.ScaleX(w, vbHimetric, vbTwips)
h = f.ScaleY(h, vbHimetric, vbTwips)
w = w + f.Width - f.ScaleWidth
h = h + f.Height - f.ScaleHeight
f.Move f.Left, f.Top, w, h 'Resizes the form - All X, Y coordinates...
f.ScaleMode = 0 'Returns f.ScaleMode to User...
Case 1 'the form to be sized is in ScaleMode 1, Twips - Doesn't need to be converted...
w = f.ScaleX(w, vbHimetric, vbTwips) 'Converts the HiMetric width to Twips - vbTwips because ScaleMode of the form is set to 1 - Twips
h = f.ScaleY(h, vbHimetric, vbTwips) 'Converts the HiMetric height to Twips - vbTwips because Scale Mode of the form is set to 1 - Twips
w = w + f.Width - f.ScaleWidth 'Adds the border width offset -ScaleWidth IS THE INSIDE OF THE FORM, Width IS THE ENTIRE FORM!!!
h = h + f.Height - f.ScaleHeight 'Adds the border height offset - ScaleHeight IS THE INSIDE OF THE FORM, Height IS THE ENTIRE FORM!!!
f.Move f.Left, f.Top, w, h 'Resizes the form - All X, Y coordinates...
Case 2 'the form to be sized is in ScaleMode 2, Points
f.ScaleMode = 1 'Temporarily resets f.ScaleMode to Twips for manipulation...
w = f.ScaleX(w, vbHimetric, vbTwips)
h = f.ScaleY(h, vbHimetric, vbTwips)
w = w + f.Width - f.ScaleWidth
h = h + f.Height - f.ScaleHeight
f.Move f.Left, f.Top, w, h 'Resizes the form - All X, Y coordinates...
f.ScaleMode = 2 'Returns f.ScaleMode to Points...
Case 3 'the form to be sized is in ScaleMode 3, Pixels
f.ScaleMode = 1 'Temporarily resets f.ScaleMode to Twips for manipulation...
w = f.ScaleX(w, vbHimetric, vbTwips)
h = f.ScaleY(h, vbHimetric, vbTwips)
w = w + f.Width - f.ScaleWidth
h = h + f.Height - f.ScaleHeight
f.Move f.Left, f.Top, w, h 'Resizes the form - All X, Y coordinates...
f.ScaleMode = 3 'Returns f.ScaleMode to Pixels...
Case 4 'the form to be sized is in ScaleMode 4, Characters
f.ScaleMode = 1 'Temporarily resets f.ScaleMode to Twips for manipulation...
w = f.ScaleX(w, vbHimetric, vbTwips)
h = f.ScaleY(h, vbHimetric, vbTwips)
w = w + f.Width - f.ScaleWidth
h = h + f.Height - f.ScaleHeight
f.Move f.Left, f.Top, w, h 'Resizes the form - All X, Y coordinates...
f.ScaleMode = 4 'Returns f.ScaleMode to Characters...
Case 5 'the form to be sized is in ScaleMode 5, Inches
f.ScaleMode = 1 'Temporarily resets f.ScaleMode to Twips for manipulation...
w = f.ScaleX(w, vbHimetric, vbTwips)
h = f.ScaleY(h, vbHimetric, vbTwips)
w = w + f.Width - f.ScaleWidth
h = h + f.Height - f.ScaleHeight
f.Move f.Left, f.Top, w, h 'Resizes the form - All X, Y coordinates...
f.ScaleMode = 5 'Returns f.ScaleMode to Inches...
Case 6 'the form to be sized is in ScaleMode 6, Millimeters
f.ScaleMode = 1 'Temporarily resets f.ScaleMode to Twips for manipulation...
w = f.ScaleX(w, vbHimetric, vbTwips)
h = f.ScaleY(h, vbHimetric, vbTwips)
w = w + f.Width - f.ScaleWidth
h = h + f.Height - f.ScaleHeight
f.Move f.Left, f.Top, w, h 'Resizes the form - All X, Y coordinates...
f.ScaleMode = 6 'Returns f.ScaleMode to Millimeters...
Case 7 'the form to be sized is in ScaleMode 7, Centimeters
f.ScaleMode = 1 'Temporarily resets f.ScaleMode to Twips for manipulation...
w = f.ScaleX(w, vbHimetric, vbTwips)
h = f.ScaleY(h, vbHimetric, vbTwips)
w = w + f.Width - f.ScaleWidth
h = h + f.Height - f.ScaleHeight
f.Move f.Left, f.Top, w, h 'Resizes the form - All X, Y coordinates...
f.ScaleMode = 7 'Returns f.ScaleMode to Centimeters...
Case Else
MsgBox "Problem With ScaleMode In SizeTheForm!"
End Select
End Property
|