Workaround for forcing the Paint Event in the Form Resize Event

The Paint Event is not called in the Case of a Control's Resize Event. Read on to know the workarounds for this problem.

The Paint Event is not called in the Case of a Control's Resize Event. Read on to know the workarounds for this problem.

Many of us write the common graphics code in the Form's Paint event, for the benefits that the Paint Event handler provides access to the Graphics object and also that it is fired whenever the form is redrawn(first shown and restored from its minimized state).

But it fails,when the form is resized. The Paint event is not triggered in the case of a Form Resize.

To solve this problem you have two workarounds..

1) Use the handy Invalidate() Method which causes the paint message to be sent to the form As a result of this, the Paint handler is called.

2) Use the "ResizeRedraw" property of control(Form) to redraw itself when the control is resized. Set it it true either in the constructor or the Main() Method.

Please Note: 

When you call the Invalidate() method without any parameters, the Paint event is called for the entire area.

If only a particular portion of the control needs to be refreshed, then call it with a Rectangle parameter that specifies the               portion of the control, otherwise it would hit the performance of the application.

By [)ia6l0 iii   Popularity  (1769 Views)