Reputation: 29
I'm dynamically creating and adding controls to a GroupBox. The GroupBox contains a single panel (Parent Panel) which fills the GroupBox. Within this Parent Panel, i have multiple child panels. It all looks and works as expected until i add 108 child panels to the Parent Panel. When this amount (or more) of child panels are added, each of the child panels suddenly becomes ugly (random black borders appear around some of the child panels, scrolling to the bottom shows black "blobs" everywhere). I can even see my windows desktop suddenly start showing on it!!! Is there a limit to the number of panels/controls that can be added to the a GroupBox?
My spec is windows 10 Pro, visual studio 2017, .NET 4.7, 16gig ram. I've tried all sorts of permutations (assumed the 108th entry was corrupt and skipped it, tried adding child panels in reverse order). It seems like its not what is being added to the panel but the number of items. When i split the child panels over 2 groupBoxes, it works fine. But i want one groupBox to have all the data though.
Upvotes: 0
Views: 265
Reputation: 29
Turns out that the parent panel was a custom panel that had a custom way of rendering child controls. It was attempting to auto calculate the panel heights in a weird way hence the weird output. However I've discovered another issue related to panels which I'll post
Upvotes: 0
Reputation: 5986
Yes, there is a limit, the limit is for the entire session of the application.
every control is a GDI Object
, the limit is very far and if you pass it something is wrong with the architecture of your application and an exception will be thrown.
instead of using controls
use System.Drawing.Graphics class when you can in order save resources.
from MSDN (GDI Objects ):
There is a theoretical limit of 65,536 GDI handles per session. However, the maximum number of GDI handles that can be opened per session is usually lower, since it is affected by available memory.
Note that you can check how many GDI objects you create using windows task manager, add this columns:
Upvotes: 0