How to make the timer rectangle (rectangle) drawn in x from 10 to 100, for example?

    1 answer 1

    Take PaintBox (as the most optimal for drawing). Add a private variable to the form, int xpos; Also take a timer. adjust the interval. Now we need to write two handlers. First for the timer

    xpos = xpos + 10; if (xpos > 100) xpos = 0; PaintBox1->Invalidate; 

    The first two lines change the coordinate. The third tells PaintBox1 to upgrade.

    now for PaintBox1.onPaint. It will be called when the system needs to refresh its view (or when we asked for it using Invalidate).

     PaintBox1->Canvas->Rectangle(xpos, 10, xpos+20, 30); 

    Everything, we start, we enjoy

    • Thanks It works. - woland
    • Another question: I have a graph in a loop from n rectangle of different lengths, how to make them draw to the end and not disappear? - woland