In my case I have 2D ArrayList full of objects that have data which is used when drawing horizontal lines, vertical lines and filled rectangles. In different cases the amount of objects is different and the image has a different amount of drawn lines and rectangles. But the image needs to be redrawn sometimes. The more stuff there is to redraw, the stronger the flashes on the screen (I hope you can figure out what I mean with “flashes”).
I have already tried double buffering, but I don’t think I’m doing it right- the type of the flashes only changes… But that’s not the current case.
I have read that it’s easy to add and remove elements (no matter the type) anywhere from the ArrayList, but the access to them is hard. I have also read that the List performs better that the ArrayList (does that mean that the program will require less resources fro the computer?), but it’s only easy to add and remove elements from the end. But I’m not sure if the Array’s performance is the fastest. And this is making me think that the flashes can become weaker if I change the ArrayList with an Array or List.
It won’t be a problem in my case because all the elements that I store in the ArrayList are form the same class.
My question is: Can I weaken the flashes if I replace the ArrayList with an Array or List?
OK, two problems here. The ArrayList vs. List question has no effect on “flashing”, since the difference in performance is small. If your list items are all of the same type or if they all derive from a common base type other than
objector if they all implement a common interface, thenList<T>is the better choice. This is because less castings or even boxings/unboxings are involved. In addition, it will be easier to access your items.Flashing: Do all your drawing in a paint-event method (of your form or of some control). Then call the
Invalidatemethod of this form or control. Don’t draw “directly”. As an improvement, you can pass a rectangle structure to Invalidate, telling which part has to be redrawn. In the paint method, you can then check e.ClipRectangle, which tells you which part has to be redrawn. This gives you the opportunity to make some improvements here. However, be aware of the fact, that the Windows OS itself can trigger an Invalidate, which results in arbitrary ClipRectangles.