[Mono-winforms-list] Dynamic drawing of Images on the form

Maser, Dan Dan.Maser at inin.com
Wed Sep 12 10:08:50 EDT 2007

   In most cases, yeah.  In my experience the decision is made based on how often the images change.  If there's at least 1s between images changing, then I prefer the Invalidate route and let them get painted according to the natural paint process.  If it's intended to be an animation or pseudo-animation with 4 images per second or more then I get a better effect by constructing the Graphics and painting directly outside of the OnPaint handler.  

-----Original Message-----
From: Rolf Bjarne Kvinge [mailto:rolflists at ya.com] 
Sent: Wednesday, September 12, 2007 9:06 AM
To: Maser, Dan; 'Abir Bhattacharya'; mono-winforms-list at lists.ximian.com
Subject: RE: [Mono-winforms-list] Dynamic drawing of Images on the form




>B. you can code up the OnPaint function to paint the correct ONE of 
images.  Then you can make a Timer object on your form.  When the timer fires, you can call the static Graphics.FromHwnd to get a graphics object and directly >paint the newer image.  Also update a member variable with the current image so that if your window is covered and uncovered it will paint the correct thing.

Instead of directly drawing the image, in this case use Invalidate
(ImageRectangle) which will cause OnPaint to be called, thereby avoiding Graphics.FromHwnd.

From: mono-winforms-list-bounces at lists.ximian.com
[mailto:mono-winforms-list-bounces at lists.ximian.com] On Behalf Of Abir Bhattacharya
Sent: Wednesday, September 12, 2007 6:16 AM
To: mono-winforms-list at lists.ximian.com
Subject: [Mono-winforms-list] Dynamic drawing of Images on the form HI, 

I need to display some dynamic images on a windows form at regular intervals based on some logic. The code runs perfectly fine with .NET and as well as the Win MONO(1.2.4) platforms , but when I port the identical code to the Mono develop running on the Linux (2.6.22-Fedora) the images are displayed in sporadic bursts . 

The code snippet:
protected override void OnPaint(PaintEventArgs e)
            Graphics gr ,gf;
            gr = e.Graphics;
            gf = Graphics.FromHwnd(this.Handle);

            for (; intCtr < Cntr; intCtr += 1)

                // call the final rect
                //passEncStr = enS.EnCodeString((string)a2[intCtr]);
                gf.FillRectangle(new SolidBrush(this.BackColor), this.ClientRectangle);

                if (intCtr == Cntr - 1)
                    intCtr = 0;




I s there a problem with the primary thread Sleep methods ?

-- Visit us at http://www.2pirad.com/ --

More information about the Mono-winforms-list mailing list