Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 2005 > Pro Visual Basic 2005
Pro Visual Basic 2005 For advanced Visual Basic coders working in version 2005. Beginning-level questions will be redirected to other forums, including Beginning VB 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro Visual Basic 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old August 7th, 2006, 09:44 AM
Registered User
Join Date: Mar 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default Resizing controls in a ScrollableForm Layout Event

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
    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
    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.

Similar Threads
Thread Thread Starter Forum Replies Last Post
Resizing the controls AccessAasif@aol.com C# 1 December 12th, 2007 05:25 AM
Raise Event From Dynamic Controls netwizard_01 ASP.NET 1.0 and 1.1 Basics 1 August 3rd, 2006 06:50 AM
Event creation for dynamically created controls sk80 Pro VB 6 2 February 7th, 2006 07:55 AM
Is there an Event for resizing the main XL window? labdad Excel VBA 2 January 6th, 2006 07:23 PM
buggy event firing in ActiveX controls pgtips Pro VB 6 6 July 10th, 2003 02:38 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.