[Mono-winforms-list]System.Windows.Forms.Form:PaintEventHandleris called only when youincrease the form

Dmitriy ddmk at r66.ru
Thu Nov 3 02:10:14 EST 2005


> In the specific case of the OnSizeChanged event, it is probably better to
> use Invalidate() unless you have some special reason to force a full
> repaint on every single mouse movement. If you can draw quickly enough,
> doing so could produce an aesthetically pleasing animated scaling effect.
> If you aren't concerned so much with that, though, you will use far less
> CPU time by using Invalidate() (or, better, by having the framework call 
> it
> for you by setting ControlStyles.ResizeRedraw when the control is 
> created).

My tests with Invalidate on Microsoft.NET shows one big problem.
If i try to repaint screen as fast as possible i have twice more FPS without 
Invalidate with same CPU usage(100%).
Furthermore if windows is fully hidden, then, if i use Invalidate,  CPU 
usage is 0% and no paint event appears (this is correct), but if part of 
window is showing Invalidate spend CPU time corresponding to square of 
viewable size.
I don't understand why microsoft don't use hardware acceleration in such 
cases.

Is something like this on mono too?



----- Original Message ----- 
From: "Jonathan Gilbert" <2a5gjx302 at sneakemail.com>
To: <mono-winforms-list at lists.ximian.com>
Sent: Thursday, November 03, 2005 5:29 AM
Subject: Re: 
[Mono-winforms-list]System.Windows.Forms.Form:PaintEventHandleris called 
only when youincrease the form


> At 10:18 AM 02/11/2005 -0500, Robert Havens wrote:
> [snip]
>> [..] But DO NOT paint from anywhere else.
>
> To the best of my knowledge, the use of 'Refresh()' or code such as:
>
> using (Graphics g = base.CreateGraphics())
> {
>  g.DrawWhatever(..);
>  ...
> }
>
> ..is not only legal but considered best practice for applications whose
> display changes frequently. While GUI widgets cannot be altered outside of
> the UI thread, System.Drawing has no such restriction and places only a 
> few
> requirements, mostly of the form that two threads may not be using the 
> same
> object concurrently. Mono has supported painting by means of
> CreateGraphics() or Refresh() for a long time, and I regularly test
> applications of mine which use this technique.
>
> The reason these methods of painting are preferable to Refresh() is that
> the message used by Invalidate() goes onto the same queue as any other
> window message, including keyboard & mouse events. If it takes long enough
> to repaint the display for more than one subsequent input event to be
> generated, the system quickly degenerates with increasingly large numbers
> of input events separating the paint messages. The framerate needlessly
> drops, essentially to zero given busy enough input. Using Refresh() or
> CreateGraphics(), on the other hand, provides for immediate lag-free 
> update
> of the display.
>
> In general, also, Refresh() is preferable to CreateGraphics() for anything
> other than simple bitmap blitting because it respects
> ControlStyles.DoubleBuffer, passing a Graphics to the OnPaint event which
> draws off-screen.
>
> In the specific case of the OnSizeChanged event, it is probably better to
> use Invalidate() unless you have some special reason to force a full
> repaint on every single mouse movement. If you can draw quickly enough,
> doing so could produce an aesthetically pleasing animated scaling effect.
> If you aren't concerned so much with that, though, you will use far less
> CPU time by using Invalidate() (or, better, by having the framework call 
> it
> for you by setting ControlStyles.ResizeRedraw when the control is 
> created).
>
> Jonathan Gilbert
> _______________________________________________
> Mono-winforms-list maillist  -  Mono-winforms-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-winforms-list 



More information about the Mono-winforms-list mailing list