Subject: Resizing controls in a ScrollableForm Layout Event
Posted By: decyclone Post Date: 8/7/2006 9:44:15 AM
Hi friends,

I was working on a form that listed a set of images(up to around 500 images).
I wanted the form to be scrollable and resize images to maintain their width to the form's width and set the height to match the 4:3 ratio and change them on layout event.
So i wrote the following code.


Class ABC
    Inherits Form
    Private Sub ABC_Layout(ByVal sender As Object, ByVal e As System.Windows.Forms.LayoutEventArgs) Handles Me.Layout
        Dim W As Integer, H As Integer, M As Integer
        Dim i As Integer = 0

        M = 20 ' Margin
        W = ClientSize.Width - (M * 2)
        H = CInt(W * 3D / 4D) ' 500

        For Each Ctrl As Control In Me.Controls
            Ctrl.Location = New Point(M + AutoScrollPosition.X, (i * (H + M)) + AutoScrollPosition.Y)
            Ctrl.Size = New Size(W, H)
            i += 1
        Next
    End Sub

    Private Sub ABC_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim W As Integer, H As Integer, M As Integer
        M = 20 ' Margin
        W = ClientSize.Width - (M * 2)
        H = CInt(W * 3D / 4D) '500
        Me.AutoScroll = True
        Me.AutoScrollMargin = New Size(M, M)
        For i As Integer = 0 To (500 - 1)
            Dim NewPicture As New PictureBox
            NewPicture.Location = New Point(M + AutoScrollPosition.X, (i * (H + M)) + AutoScrollPosition.Y)
            NewPicture.Size = New Size(W, H)
            NewPicture.BorderStyle = BorderStyle.FixedSingle
            NewPicture.Name = "Picture #" & (i + 1).ToString
            NewPicture.ImageLocation = "Image" & (i + 1).ToString & ".jpg"
            NewPicture.SizeMode = PictureBoxSizeMode.StretchImage
            Me.Controls.Add(NewPicture)
        Next
    End Sub
End Class


the problem is (wether i set AutoScrollMinSize manually or not),
the images overlap each other after some point.
that is in my test, images are around 1024x768 resolution,
so after around image # 45 in all the images Control.Location.Y property remains the same(or what).
so after i scroll down to end of vertical scroll, i get image# 45. All other after it are hidden behind it. I hope u guys can understand it.

If u can't get the problem, u simply paste the given code in IDE and first guess the results and then see the actual results.

Please help me.

Go to topic 48062

Return to index page 210
Return to index page 209
Return to index page 208
Return to index page 207
Return to index page 206
Return to index page 205
Return to index page 204
Return to index page 203
Return to index page 202
Return to index page 201