• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 174
  • Last Modified:

Image Control Resizing

I'm using an array of Images controls that are loaded at run time from 0-99.  I want all of them to resize to the window in a 10 by 10 square when the window is resized, but they don't.  I think that this is because the stretch property is set to True.  Here is the code:

Private Sub Form_Resize()
    On Error Resume Next
    For I = 1 To H * W
        Unload MazPiece(I)
    Next I
End Sub

Public Sub MakeBoxes()
    A = ToolBar(8).Left + ToolBar(8).Width + 500 'Left Buffer
    WID = (Me.Width - A - 400) / W
    HEI = (Me.Height - 900) / H
    MazPiece(0).Height = HEI
    MazPiece(0).Width = WID
    MazPiece(0).Visible = True
    For I = 1 To H * W
        Load MazPiece(I)
        MazPiece(I).Width = WID
        MazPiece(I).Height = HEI
        MazPiece(I).Visible = True
    Next I
    Whatever = 0
    For Y = 1 To W
        For X = 1 To H
            Whatever = Whatever + 1
            MazPiece(Whatever).Left = ((X - 1) * WID) + A
            MazPiece(Whatever).Top = ((Y - 1) * HEI)
            MazPiece(Whatever).Picture = PicClip.GraphicCell(14)
        Next X
    Next Y
End Sub
1 Solution
Hi VBTom,
  I think I found the answer.
When I tried a code that is pretty the same like yours, I found that I cannot Unload objects that are placed on the form during the Form_Resize or Form_Paint events.
 So the Unload cicle in your Form_Resize event doesn't do anything and the On Error Resume Next make's it jump over without sending an error.
 So if you remove the statement On Error Resume Next, an error should appear. (Yes?).
  So I recommend when resizing the form, do not Unload any objects.
 Just make them invisible:

Then in MakeBoxes change their coordinates and Width and Height
  ImageX.Left= ...
  ImageX.Top= ...
  ImageX.Width= ...
  ImageX.Height= ...

  just make all the Images visible:


You'd better use the Load ImageX statement in your Form_Load event.
Do not use Load or Unload statements in
your Form_Resize or Form_Paint events.

Use the Visible=True, Visible=False
property instead.

             Pavel Tsekov
          email : paul_tsekov@yahoo.com
VBTomAuthor Commented:
Thank you.  It worked just like I wanted it to.  I also found another answer that does the same thing elsewhere.  That answer is to make ImageX.Picture = LoadPicture("").  They both do the same thing though I'm not sure which one is faster.

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now