0

I have a flowlayoutpanel with thousands of pictureboxes and even more buttons. I am looking for a way to not load the controls while they are outside the screen so that I don't have to wait for all the controls to load. Much like windows explored folder view works if you have say, a thousand files in a folder, you don't need to wait for all of them to load and display thumbnails.

The code and the way I am generating controls at the moment is:

For Each myDirectory As IO.DirectoryInfo In New IO.DirectoryInfo(ProjectsFolder & SmartHub_Home.ComboBox_Subcategory.SelectedItem & "\").GetDirectories().Reverse


'Programmatically creating controls
Next
Eduards
  • 68
  • 2
  • 20
  • 2
    _flowlayoutpanel with thousands of pictureboxes and even more buttons_ Please reconsider the design. 1000+ control in a Form leads to a disaster. – dr.null Jan 17 '22 at 16:49
  • 1
    What I would consider is something more like a tab/page control with a FLP on each tab. Read the directory content (File path & Names) in List and calculate how many tabs are required, then when the tab is activated using the Take() function Select the the files from the above list and process the images for display and destroy any previously active content. What dr.null says is true, if you start displaying 1000s of GUI controls you're going to run into trouble fast – Hursey Jan 17 '22 at 20:01
  • Like I explained, imagine having a thousand files in a particular folder, it loads instantly and scrolls flawlessly, that's essentially what I am after – Eduards Jan 17 '22 at 20:14
  • Lazy loading will not be enough. If you load all those controls at any point then things will grind to a halt. What you really need to do is remove controls as they move out of view and add them as they move into view. That will keep the number of controls relatively low at all times. There is no specific in-built way to do that so you will need to give the problem some thought, implement what you can and then post a question when you encounter an actual issue. –  Jan 18 '22 at 00:20
  • 3
    See [this](https://stackoverflow.com/a/39810717/14171304) answer. – dr.null Jan 18 '22 at 01:39
  • Thanks, but I need it in VB not C# – Eduards Jan 18 '22 at 13:13
  • 2
    That code looks trivial to convert to VB. I didn't see anything idiomatic or that requires experience to identify how it converts. You should have a basic understanding of C# to work in the .NET ecosystem, even if it's not your primary language. – Craig Jan 18 '22 at 17:36
  • 1
    @Craig Also there are plenty of online C# to VB convert tools that will do 99% of the work for you - that last 1% is just edge cases that don't currently convert certain lines correctly. – B.O.B. Feb 10 '22 at 04:04
  • What you see in Windows Explorer is not thousands of PictureBoxes and Buttons in a FlowLayoutPanel, it's some kind of ListView. – Reza Aghaei Feb 12 '22 at 23:57
  • 1
    While the C# linked post is an interesting answer, but since it creates all the controls and keep them in a list, then it will not solve your problem in case of having too many controls. – Reza Aghaei Feb 12 '22 at 23:58
  • So how does one solve it? – Eduards Feb 13 '22 at 10:17

0 Answers0