controls.Add

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I use very often custom controls in panels.
But I always have performance issues (on all computer, not only on mine).

I always have this kind of code :

panel1.controls.clear
While ...
r = New uMyControl(param1,param2)
Panel1.Controls.Add(r)
r.Dock = DockStyle.Top
Panel1.Controls.SetChildIndex(r, 0)
End While

I tried to build a list of controls first and then use the control.addRange
method. But it seems that the increase of performance is just 5-10%. It is
still too slow, especially when the the size of controls is more than 20.

What is the best trick to improve that ?

Thanks
 
Hi Stivo,

I use a code similar to your and it works fine on a PPC device, these are
some hints that may or may not help you
1- Use Control.Add only, no SetChildIndes , why are you using this method in
the first place??? This is a VERY heavy operation I think, just remove it
and the performance will increase !!!

2- use Control SuspendLayout/ ResumeLayout on the panel around the while
loop


Cheers,
 
Thanks for your post Ignacio !

Here is my answer:

1) I use SetChildIndex to put again the right order. Ok, I admit that I can
avoid to use SetchildIndex by inverting the order in which I create the
control, but I like to have a code as logical as it can.

2) I already tried SuspendLayout and ResumeLayout(true), but very often
(it's working only in a few cases) the docking is no more working. Eventhough
I call ResumeLayout(true) to resume the layout the docking is not respected
and all controls are behind each other, we can see only one in the panel.

I have framework .NET 1.1
 
Stivo said:
Thanks for your post Ignacio !

Here is my answer:

1) I use SetChildIndex to put again the right order. Ok, I admit that I can
avoid to use SetchildIndex by inverting the order in which I create the
control, but I like to have a code as logical as it can.

This has NOTHING to do with code logicalness , it's a huge overload, drop
it !!!

cheers,
 
Back
Top