
Wanna get Resize event to trigger procedure to Load/Unload ctrls
The code you already have, that places the thumbnails based on
size, could be moved to the Resize event, which is fired after
the Form_Load. The only thing you have to change is the unloading
of any extra images. VB will not allow it in the Paint, or Resize
events. Use a timer to allow these events to complete before
unloading the extra images.
EXAMPLE: On a new form place a Timer and an Image control. Paste
any thumbnail image into the image control and set its Index
property to 0. Then paste in this code and give it a try! Click
on the form to see how many images are currently in memory.
Option Explicit
Dim LastImage%
Private Sub Form_Click()
Dim Nxt%
On Error GoTo ShowAnswer
Do
If Image1(Nxt).Enabled = True Then Nxt = Nxt + 1
Loop
ShowAnswer:
MsgBox CStr(Nxt) & " images loaded."
End Sub
Private Sub Form_Load()
Timer1.Interval = 1
Timer1.Enabled = False
On Error GoTo Prompt
Image1(0).Visible = False
Exit Sub
Prompt:
MsgBox "Change Image1.Index to 0 before running program."
End
End Sub
Private Sub Form_Resize()
Const Padding = 180 'Working in Twips (Default)
Dim XX&, YY&, NextImage%, ImgTot%
Dim ImgSizeX&, ImgSizeY&
Cls
MousePointer = vbHourglass
ImgSizeX = Image1(0).Width
ImgSizeY = Image1(0).Height
For YY = Padding To (ScaleHeight - ImgSizeY - (Padding \ 2)) Step (ImgSizeY + Padding)
For XX = Padding To (ScaleWidth - ImgSizeX - (Padding \ 2)) Step (ImgSizeX + Padding)
On Error Resume Next
Load Image1(NextImage)
Image1(NextImage).Visible = False
Image1(NextImage).Move XX, YY
CurrentX = XX
CurrentY = YY - 180
Print NextImage
NextImage = NextImage + 1
Next
Next
LastImage = NextImage - 1
For NextImage = 0 To LastImage
Image1(NextImage).Visible = True
Next
On Error GoTo Bailout
Do
Image1(NextImage).Visible = False
NextImage = NextImage + 1
Loop
Bailout:
MousePointer = vbDefault
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Dim Nxt%
Timer1.Enabled = False
Nxt = LastImage
On Error GoTo Bailout
Do
Nxt = Nxt + 1
Unload Image1(Nxt)
Loop
Bailout:
End Sub
Quote:
> Peter,
> Thanks for your reply. But I'm afraid that I didn't define the problem
> very clearly. I'm sorry. This issue isn't the original loading of the
> controls. It's adding or removing (via Load and Unload) controls from
> the form as a response to a Resize of the form.
> I load the image and text controls at Form Load time, based on the size
> of the form at that time. But if the user maximizes the form, I want to
> put more thumbnails on it and if he/she re-windowizes it then I want to
> unload some controls. I'm having a hard time understanding why VB won't
> let you do this. It seems like one of many natural responses to a
> Resize.
> Jerry