Link to home
Create AccountLog in
Avatar of JamesBrian
JamesBrian

asked on

Timer vs Form/Controls resizing

Hi all,

in a previous question ,
https://www.experts-exchange.com/questions/22010941/form-control-resize-vs-SSTab.html
I was having some problems with the resizing.

Everything is working fine now, but now I added a Timer control.
And I keep getting errors at this line :

               ctl.Left = x_scale * .Left
I guess this is because the timer control that is sitting on the form is'nt a real control...?
Anyway, I screws up everything, and even when I catch the error by its number (382), and just say :

errorhandler:
If Err.Number = 382 Then
Err.Clear
Resume Next
End If

That enables the app to load , but the resizing doesn't work anymore when doing that.

Any suggestions?

thx,

JB

Avatar of drydenhogg
drydenhogg

382 - property can not be set at runtime, but check for altering the height / width on the timer control, that would be a different error code (438 from my test) which the error handler does not catch and the resize event terminates.

you would need to catch the 438 event, or alternatively check which control you are adjusting before attempting to adjust it.
Hi JamesBrian,

       With m_ControlPositions(i)
           If TypeOf ctl Is Line Then
               ctl.X1 = x_scale * .Left
               ctl.Y1 = y_scale * .Top
               ctl.X2 = ctl.X1 + x_scale * .Width
               ctl.Y2 = ctl.Y1 + y_scale * .Height
           ElseIf Not(TypeOf clt Is Timer) Then
               ctl.Left = x_scale * .Left
               ctl.Top = y_scale * .Top
               ctl.Width = x_scale * .Width
               If Not (TypeOf ctl Is ComboBox) Then 'This will ignore your timer control
                   ' Cannot change height of ComboBoxes.
                   ctl.Height = y_scale * .Height
               End If
               On Error Resume Next
               ctl.Font.Size = y_scale * .FontSize
               On Error GoTo 0
           End If
       End With

Tim Cottee
Avatar of JamesBrian

ASKER

Nope.

Now all my controls are gone. I get empty screens.
Also,
there is a typo in this line:
     ElseIf Not(TypeOf clt Is Timer) Then

where clt must be ctl

The error 438 does'nt solve the problem either
JB
438 is just one of the different error codes you can be thrown, which is why checking the control before setting is the better way. If all the controls vanished I would suspect they got set off the screen, or to 0 height / 0 width.

What are you setting the x_scale / y_scale to, if possible, post your resize event please.
ASKER CERTIFIED SOLUTION
Avatar of TimCottee
TimCottee
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
No.
Screen remain empty.

When I change the code back, everything is visible again.

JB
This is what it needed:

   For Each ctl In Controls
         If Not (TypeOf ctl Is Timer) Then
     With m_ControlPositions(i)
           If TypeOf ctl Is Line Then
               ctl.X1 = x_scale * .Left
               ctl.Y1 = y_scale * .Top
               ctl.X2 = ctl.X1 + x_scale * .Width
               ctl.Y2 = ctl.Y1 + y_scale * .Height
           Else
               ctl.Left = x_scale * .Left
               ctl.Top = y_scale * .Top
               ctl.Width = x_scale * .Width
               If Not (TypeOf ctl Is ComboBox) Then
                   ' Cannot change height of ComboBoxes.
                   ctl.Height = y_scale * .Height
               End If
               On Error Resume Next
               ctl.Font.Size = y_scale * .FontSize
               On Error GoTo 0
           End If
       End With
       End If
       i = i + 1
   Next ctl

==exclude the Timer from this routine.

I'm gonna award points to Tim Cottee for the TypeOf idea...