Wanna get Resize event to trigger procedure to Load/Unload ctrls 
Author Message
 Wanna get Resize event to trigger procedure to Load/Unload ctrls

I'm putting thumbnails on a form.  The size of the form dictates the
number of thumbnails the form will hold.  Since I can't Unload or Load
controls during a Resize, I'm trying to figure a way for the Resize
event  to trigger another procedure (or event) that would execute AFTER
the Resize and do the Load/Unload.  Any ideas?

Thanks,
Jerry



Thu, 15 Feb 2001 03:00:00 GMT  
 Wanna get Resize event to trigger procedure to Load/Unload ctrls
Jerry,

I would use the Form_Activate event as the point at which you want to load
your controls.  Be careful though as the Form_Activate can get triggered by
other events besides the initial display, so I would use something like:

Option Explicit
Dim l_bSetUpControls As Boolean

Private Sub Form_Activate()
  Dim i%
  Dim Thistop!
  Dim nControls%

  If l_bSetUpControls Then Exit Sub

  l_bSetUpControls = True

  Thistop! = Text1(0).Top
  nControls% = 1
  While Thistop! + Text1(0).Height + 100 < Me.Height
    Load Text1(nControls%)
    Text1(nControls%).Left = Text1(0).Left
    Thistop! = Thistop! + 300
    Text1(nControls%).Top = Thistop!
    Text1(nControls%).Visible = True
    nControls% = nControls% + 1
  Wend

End Sub

Private Sub Form_Load()
  l_bSetUpControls = False
End Sub

HTH

Peter

Quote:

>I'm putting thumbnails on a form.  The size of the form dictates the
>number of thumbnails the form will hold.  Since I can't Unload or Load
>controls during a Resize, I'm trying to figure a way for the Resize
>event  to trigger another procedure (or event) that would execute AFTER
>the Resize and do the Load/Unload.  Any ideas?

>Thanks,
>Jerry



Fri, 16 Feb 2001 03:00:00 GMT  
 Wanna get Resize event to trigger procedure to Load/Unload ctrls
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



Fri, 16 Feb 2001 03:00:00 GMT  
 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



Sat, 17 Feb 2001 03:00:00 GMT  
 Wanna get Resize event to trigger procedure to Load/Unload ctrls
Thanks for your help, Larry.  This did the trick very nicely!

Jerry



Sat, 17 Feb 2001 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Event Triggered from User resizing a column on a MSHFlexgrid

2. Unload controls on Resize event

3. Is it possible to trigger an event when a template is loaded as a global template

4. Cant get a runtime loaded user control to trigger event

5. Getting a hotkey to trigger a VB event

6. Shape Resize In Form Load Procedure

7. VB3 BUG? Unload Me causes --LOAD--event

8. Unloading Forms causing a Form Load Event???

9. Unloading Forms causing a Form Load Event???

10. "Unload" in Load Event

11. Unloading or hiding a form in the form's load event

12. Unload a form when the load event fails

 

 
Powered by phpBB® Forum Software