Board index » delphi » Form Repaint Problem Solved

Form Repaint Problem Solved

This was my statement of the problem:

The problem is that if the user moves the mouse cursor onto and off of
the Control (System) menu icon (without clicking), the form's OnPaint
event is triggered and the form is repainted.

I am using D3. The project uses several other forms; one other form
has the problem, but the others do not. The forms are all called
modally from the main form.

The solution:

I observed that if the mouse cursor was quickly moved onto and off of
the System menu icon, too quick for the Close hint to appear, the form
did not repaint. It was the closing of the Close hint (when the cursor
was moved slowly) that triggered the form's OnPaint event!

Experimenting, I found that if I put a visible component in the upper
right corner of the form, so that the Close hint appeared on top of
the visible component, the problem did not occur.

My solution is to place a blank but visible TPanel on the form, and to
then place all of the form's other components on the panel. The TPanel
is aligned with the form's client area.

Is there a better solution? Is there a way to prevent the repainting
if the Close hint is allowed to appear directly over the form?

 

Re:Form Repaint Problem Solved


Sheldon Shallon schrieb:

Quote
> I observed that if the mouse cursor was quickly moved onto and off of
> the System menu icon, too quick for the Close hint to appear, the form
> did not repaint. It was the closing of the Close hint (when the cursor
> was moved slowly) that triggered the form's OnPaint event!

Arrgh. I tried it with the mouse cursor over the system menu item, at
the left side of the caption bar. That's why nothing occurs.

Quote
> Experimenting, I found that if I put a visible component in the upper
> right corner of the form, so that the Close hint appeared on top of
> the visible component, the problem did not occur.

> My solution is to place a blank but visible TPanel on the form, and to
> then place all of the form's other components on the panel. The TPanel
> is aligned with the form's client area.

> Is there a better solution? Is there a way to prevent the repainting
> if the Close hint is allowed to appear directly over the form?

Inside the OnPaint event, check the Canvas.ClipRect rectangle. It tells
you the range to be drawn. It is always a good idea to draw only as much
as neccesary.

BTW, please don't multi-post.

-Michael

Other Threads