Tell me, please, how to circle the border of the control at the moment when it changes its size. Suppose there is a control panel with a height = 100 and a width = 0. At a certain moment, its width changes every second until it reaches a valid 100 pixels. The task is to draw a line at every second of time along the borders of this panel. For the form I use the following code:

void Opac1ty::Border_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e){ Skin^ sk = gcnew Skin; System::Drawing::Color border_color = System::Drawing::ColorTranslator::FromHtml(sk->l_p(send_forma->Name, "form", "border_color")); Pen^ pen = gcnew Pen(border_color, 2); e->Graphics->DrawRectangle(pen, 2, 2, send_forma->Width - 4, height - 4); } 

but the problem is that when the form is resized, the DrawRectangle is drawn every time the form is resized and the result is not erased every time the form is resized again, so in this code I draw only what should come out in the end.

    1 answer 1

    When changing the size of the control, only a small part of it is invalidated, namely, the one by which it has grown. Accordingly, the dimensions of the e->ClipRectangle not equal to the entire panel.

    A simple way is likely to be the disability of the entire surface of the control when it is resized. To do this, subscribe to the Resize or SizeChanged event and SizeChanged desired redraw area in it.

     private: System::Void panel1_Resize(System::Object^ sender, System::EventArgs^ e) { panel1->Invalidate(panel1->DisplayRectangle); } 

    Then the Paint event should draw the entire surface of the control.

    • Thank! Everything is clear. - Smirnov
    • There is also a problem of a purely esthetic character. The control above which this panel is located is flickering when the panel is resized. Is it possible to prevent this? - Smirnov
    • @Smirnov, DoubleBuffered should help. But it is better not to ask in the comments, but as a separate question. - Alexander Petrov