I currently have a form with a scrollable panel that potentially contains over 100 child controls (only about 10 are viewable on screen at any time)
This causes a lot of flickering when scrolling.
I have been looking at some double-buffering techniques, but they won't work in my case since I am using several child controls (Buttons, Labels, Checkboxes) and they all get painted independently. I can't do anything in the panel's OnPaint method that affect the children.
And several answers I have read state that adding existing controls take more resources rather than, say, instead of a Label, just painting a colored square with text over top.
I have 2 main questions:
1) you would get scroll_position*one_stepscroll
.you would find begining item index with scroll_position*one_stepscroll/item.height -1
and last item index with adding
constant item sizes (panel.height/item.height+1 ) .
then u would draw items to backbuffer (as u see from calculations its height will be greater than panel.height of course ) . then show that buffer on panel graphics .so this is how double buffering works .`(if your controls will contain big images to draw then you can use some lazy loading techniques. proxy pattern to speed up scrolling , check this : proxy pattern
1A)if your item.heights differ then you have find first item different way. i would suggest you for performance to store each items begining position too . this way u will reduce calculation instead of finding looping throw items and adding heights each time
2)you will get its state and show state . for example u can do . filled rectangle as for checked hollow rectangle for unchecked
.(think it will be your own object with additional boolean state property ,or just boolean variable and with its x,y,width,height ) .on panel click you will check click position with visible checkbox items areas . then you would change its state = !state
. then again you will redraw whole panel again for visible items .
3)3rd way just change contents when scrolling and use controls . and scrolling step will be one object movement . Trust me on long run user prefer easy workng over fance shamancy things. .just use 10 controls items . and 100 objects storing values for it . on scrolling you would just change those 10 items display properties (text ,state or image or whatever) from 100 objects . this way you will use controls itself .easy solution for performance and memory too.