Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

scalewidth not changing on resize 1

Status
Not open for further replies.

zemp

Programmer
Jan 27, 2002
3,301
CA
VB6 SP6
Win XP SP3

I have one form that when you resize the form (maximize or drag the form border) the width, height, scalewidth and scaleheight values do not change. As a result the controls do not resize (multiple types of controls).

The resize event does fire properly. I have checked the values in the immediate window. I have other forms where it works as expected.

My question is what would cause that to happen? Is there a property or setting I am missing? Where do I start looking.

zemp
 
Based on a brand new form in new standard exe project
[tt]
Private Sub Form_Resize()
Debug.Print Me.Width & " " & Me.Height & " " & Me.ScaleWidth & " " & Me.ScaleHeight
End Sub
[/tt]

4800 3600 4560 3060
4800 3615 4560 3075
4800 3630 4560 3090
4800 3645 4560 3105
4830 3660 4590 3120
4845 3690 4605 3150
4875 3720 4635 3180
4920 3765 4680 3225
4965 3795 4725 3255
5025 3825 4785 3285
5070 3870 4830 3330
5145 3945 4905 3405
5190 3990 4950 3450
5250 4050 5010 3510
5355 4140 5115 3600
5400 4170 5160 3630
5445 4200 5205 3660
5505 4275 5265 3735
5565 4335 5325 3795
5625 4410 5385 3870
5685 4470 5445 3930
5745 4545 5505 4005
5805 4605 5565 4065
5880 4665 5640 4125
5955 4740 5715 4200
6000 4785 5760 4245
6060 4845 5820 4305
6120 4905 5880 4365
6165 4935 5925 4395
6225 4980 5985 4440
6270 5010 6030 4470
6300 5055 6060 4515
6345 5070 6105 4530
6375 5115 6135 4575
6390 5130 6150 4590
6420 5145 6180 4605
6435 5190 6195 4650
6465 5205 6225 4665
6480 5220 6240 4680
6495 5235 6255 4695
6495 5250 6255 4710
6510 5250 6270 4710
6525 5250 6285 4710
6525 5250 6285 4710

and same for setting various properties of the form like autoredraw, scalemode, and I even tried hasdc but I am unable to recreate your problem. The only thing I can think of when it comes to the scale properties is that perhaps you are setting it somewhere in code. Thus making it user defined but that would not explain the actual width/height not changing.

Perhaps if you leave just two forms open in design view in your project and use ctrl+tab to toggle back and forth between the two, you can easily compare each forms properties with the other. Should take only a minute or so and any properties that are different will/should pop out at you.

If that does not work, then search the forms code for the scale mode properties in question. Perhaps by mistake you went...
[tt]
Me.ScaleWidth = somevalue
Me.ScaleHeight = SomeOtherValue
[/tt]



Good Luck

 
Resolved.

My application allows multiple instances of this form. So when creating the form I create an instance of it.
Code:
...
   Set frmMe = New frmMain
   frmMe.m_lngGrpID = pGrpID
   frmMe.Show
'   frmMain.m_lngGrpID = pGrpID
'   frmMain.Show
...
When I switched the code for what is now commented out it worked. So I looked again at the resize eventg and realized that I was referencing the actual form and not the instance. When I switched the reference it worked.
Code:
Private Sub Form_Resize()
'// Resize the form.
   '// SSTab control.
   Debug.Print "***BEFORE***"
   Debug.Print "TH: " & sstMain.Height & " - TW: "; sstMain.Width
   Debug.Print "FH: " & Me.Height & " - FW: "; Me.Width
   Debug.Print "FSH:" & Me.ScaleHeight & " - FSW:"; Me.ScaleWidth
   'Debug.Print "FH: " & frmMain.Height & " - FW: "; frmMain.Width
   'Debug.Print "FSH:" & frmMain.ScaleHeight & " - FSW:"; frmMain.ScaleWidth

   If WindowState <> vbMinimized Then
      txtLSOther.Width = frmMain.ScaleWidth - txtLSOther.Left - 120
      With sstMain
         .Top = 1800
         .Left = 120
         .Height = Me.ScaleHeight - .Top - 120 - stbMain.Height
         .Width = Me.ScaleWidth - .Left - 120
         '.Height = frmMain.ScaleHeight - .Top - 120 - stbMain.Height
         '.Width = frmMain.ScaleWidth - .Left - 120
      End With
   End If

   Debug.Print "***AFTER***"
   Debug.Print "TH: " & sstMain.Height & " - TW: "; sstMain.Width
      Debug.Print "FH: " & Me.Height & " - FW: "; Me.Width
   Debug.Print "FSH:" & Me.ScaleHeight & " - FSW:"; Me.ScaleWidth
   'Debug.Print "FH: " & frmMain.Height & " - FW: "; frmMain.Width
   'Debug.Print "FSH:" & frmMain.ScaleHeight & " - FSW:"; frmMain.ScaleWidth

End Sub
Thanks vb5, your using Me. as a reference triggered a brain cell to funtion properly.


zemp
 
Or just drop the Me since it isn't needed. Overqualifying "self" properties leads to lots of problems of this nature, especially when reusing code.
 
Please correct me if I am wrong, but Me is implied when referencing properties of the current form and thus using Me makes no difference. The difference comes in when you use formName.Property and have created multiple instances of the form via the
[tt]
Dim F As Form
Set F = New Form1
F.Show
[/tt]
method, as Zemp admittedly got caught with when he used formname.property in the resize event of the created instance.

As an example... New standard exe project, add a button to Form1(Command1), add the code, run...
[tt]
Option Explicit

Private Sub Command1_Click()
Dim F As New Form1
F.Show
End Sub

Private Sub Form_Resize()
Debug.Print Form1.Width & " " & Me.Width
End Sub
[/tt]

Now, resize the new instance of the form and you will see that Me refers to the correct instance of the form, Always! So to say that getting rid of Me would be the incorrect thing to say, but instead say, that using actual formname is/will be the problem.
 
Within the Form these properties are already members of the current namespace.

Using Me all over is like using VBA as a qualifier on the numerous methods that library supports. It's visual pollution more than anything else:
Code:
    Dim I As Integer
    
    I = VBA.CLng("1234")
    VBA.MsgBox VBA.CStr(I), VBA.VbMsgBoxStyle.vbOKOnly
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top