Quote:
> I'm resizing a form at runtime using Screen.Width /2 etc. I can get a
> Listbox to take up a fifth of the screen by calculation, but what's the way
> to position it? (Still searching the database). Ideally I want a ListBox at
> the right hand side of a form which I've just told to resize itself to the
> full screen width and height. Help appreciated.
Here is a generalized resizing routine....
Hope this helps
George
----------------------------------------------------
Option Explicit
Dim Scaler!, AllScale!
Dim Form1W%, Form1H%
Dim CtlL%(), CtlT%(), CtlW%(), CtlH%(), CtlF%()
Dim Ctl As Control
'Const Larger% = 43 'Plus on NumPad
'Const Smaller% = 45 'Minus on NumPad
Const Larger% = 38 'Up arrow on NumPad
Const Smaller% = 40 'Down arrow on NumPad
'
' All lines should have the form Linexx
' where xx is numeric
' example Line5, Line12
'
Private Sub Form_Load()
Dim i%
KeyPreview = True
Scaler = 1.1
AllScale = 1
' Get number of controls
For Each Ctl In Me.Controls
i = i + 1
Next
ReDim CtlL(i), CtlT(i), CtlW(i), CtlH(i), CtlF(i)
' Save locations
i = 0
For Each Ctl In Me.Controls
i = i + 1
If Left$(Ctl.Name, 4) = "Line" Then
CtlL(i) = Ctl.X1
CtlT(i) = Ctl.Y1
CtlW(i) = Ctl.X2
CtlH(i) = Ctl.Y2
Else
CtlL(i) = Ctl.Left
CtlT(i) = Ctl.Top
CtlW(i) = Ctl.Width
CtlH(i) = Ctl.Height
CtlF(i) = Ctl.FontSize
End If
Next
' Save form values
Form1W = Me.Width
Form1H = Me.Height
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = Larger Then
KeyCode = 0
If AllScale * Form1W >= Screen.Width Or AllScale * Form1H >=
Screen.Height Then Exit Sub
' New scale
AllScale = Scaler * AllScale
FormReScale
ElseIf KeyCode = Smaller Then
KeyCode = 0
If AllScale <= 1 Then Exit Sub
' New scale
AllScale = AllScale / Scaler
FormReScale
End If
End Sub
Private Sub FormReScale()
Dim i%
Me.Width = AllScale * Form1W
Me.Height = AllScale * Form1H
' Rescale all controls
For Each Ctl In Me.Controls
i = i + 1
If Left$(Ctl.Name, 4) = "Line" Then
Ctl.X1 = CtlL(i) * AllScale
Ctl.Y1 = CtlT(i) * AllScale
Ctl.X2 = CtlW(i) * AllScale
Ctl.Y2 = CtlH(i) * AllScale
Else
Ctl.Left = CtlL(i) * AllScale
Ctl.Top = CtlT(i) * AllScale
Ctl.Width = CtlW(i) * AllScale
Ctl.Height = CtlH(i) * AllScale
Ctl.FontSize = CtlF(i) * AllScale
End If
Next
End Sub