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
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
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
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
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
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.
What are you setting the x_scale / y_scale to, if possible, post your resize event please.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
No.
Screen remain empty.
When I change the code back, everything is visible again.
JB
Screen remain empty.
When I change the code back, everything is visible again.
JB
ASKER
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...
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...
you would need to catch the 438 event, or alternatively check which control you are adjusting before attempting to adjust it.