1

Not sure the best way to phrase the question but basically, I have a list of movies in my program and i have a custom control that represents each movie.

The custom control looks like this: https://dl.dropboxusercontent.com/u/37005139/MovieListItem.png

So for testing, I am looping through my list of movies and for each one i am adding this control to a panel at coordinates(10, yCoord), then adding the height of the panel to yCoord.

The Panels Autscroll property is set to true to be able to scroll down through the list of movies.

But when i get about halfway through my list of almost 400 movies, This happens: https://dl.dropboxusercontent.com/u/37005139/windowImage.PNG

It will not display anymore of my movies an as you can see, it is not even rendered correctly.

This is how I'm adding the controls to the panel:

For Each item In files
        Dim newControl As New MovieView(item, Panel1.Width - 28)
        newControl.Location = New Point(10, yCoord)
        Panel1.Controls.Add(newControl)
        yCoord += newControl.Height
Next

Does anybody have any ideas as to whats causing this or how to remedy the situation? The only thing i can think is that i'm out of memory, But its not throwing any exceptions and task manager seems to indicate that i have plenty of memory left.

Thanks :)

  • Not sure what's causing the problem. Perhaps you've reached the outer limit of how big/tall a Panel can get? You could try introducing some kind of paging, i.e. "Page 1 of 4" with forwards/backwards buttons? – Idle_Mind Nov 29 '14 at 08:18
  • @Idle_Mind Indeed. WinForms' `Panel` has a max height of 32,767px. – TyCobb Nov 29 '14 at 08:23
  • Interesting, My rough calculations show that what is currently being displayed is around 33000 pixels. Didnt know that panel had a max height. Really dont want to introduce pages, I might have to rethink my design. Thanks Guys. – user2735257 Nov 29 '14 at 13:12

1 Answers1

1
    newControl.Location = New Point(10, yCoord)

This is not correct for a panel that has its AutoScroll property set to True. Seems to work just fine, until you do this when the panel is partially scrolled. The Panel class implements scrolling by changing the Location property of its child controls. Which is what you have to do as well when you add controls at runtime, after the user had a chance to operate the scrollbars. Most typically after using a BackgroundWorker for example. If you don't then the control ends up in the wrong location and gets overlapped, like your image demonstrates. Fix:

    newControl.Location = New Point(10 + Panel1.AutoScrollPosition.X, _
                                yCoord + Panel1.AutoScrollPosition.Y)

FlowLayoutPanel is handy, it can do this automatically.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536