Picboxes, Rectangles, and Refresh
Posted on 2008-10-06
I want to refresh my screen (graphics0, without having to refresh the entire screen.
I am developing an application that has approx. 50 pictureboxes with gradient fill rectangles and a couple lines of text in each (the picture boxes, rectangles, text, etc are in a collection). These picture boxes are about 100 wide by 50 high not too big. I am allowing the user to MouseDown and move the picture boxes anywhere he wants on the screen. The problem I am having is when I enter the screen (activate) or just RUN the program, it seems as though the only way I can get all of the 50 picture boxes on the screen is to implement the form_Paint routine. The form_Paint routine will iterate through the loop of the dynamically created pictureboxes. This is very slow (takes about 2 seconds to generate and gives that flicker annoyance you see on the screen). Once I have the picture boxes displayed, I can use the individual picturebox_Paint function for each picture box (via an overload upon dynamic substantiation of the control).
Here is the question how do I get the picture boxes to refresh on the screen in the most time economical fashion/time (both upon Activation and during run)? And then, how do you keep them refreshed without having to loop through each of the controls multiple times?
For example, below is the OnPaint for the form where the collection of approx 50 picture boxes are written to the screen. Looking at this code, the myForm_paint function will fire approx 1750 times. Yikes! There has to be a better way?
Private Sub myForm_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Dim UI As UnitInfo
For i = 1 To RectColorsAndWords.Count
UI = RectColorsAndWords(i)
Catch ex As Exception