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

Maser, Dan Dan.Maser at inin.com
Wed Sep 12 09:36:55 EDT 2007


   I would expect this code to do strange things.  I would highly
recommend getting your logic out of the paint routine.  Specifically:
 
1. Your OnPaint should be simple, and should paint the window and
return.  No sleeps should be here, ever.
2. I would only calls the base.OnPaint once.
3. My hunch is that it's not ok to call the static Graphics.FromHwnd
from inside the OnPaint handler.  Use the Graphics object that was
passed to you, don't create another one.
4. Don't Dispose the object that gr points to - it was passed to you and
you don't own it.
 
 
I think you ahve two main choices (after fixing the above things);
 
A. you can code up the OnPaint function to paint the correct ONE of your
images.  Then you can make a Timer object on your form.  When the timer
fires, update a member variable that indicates which images is 'current'
and call Invalidate so the system will invoke your OnPaint again and
you'll paint the newer image.
 
B. you can code up the OnPaint function to paint the correct ONE of your
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.
 
 

________________________________

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)

        {

            //base.OnPaint(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]);

                PaintFinalRect(enS.EnCodeString((string)a2[intCtr]),gr);

                Thread.Sleep(100);

                base.OnPaint(e);

                gf.FillRectangle(new SolidBrush(this.BackColor),
this.ClientRectangle);

                gr.Dispose();

 

                if (intCtr == Cntr - 1)

                {

                    intCtr = 0;

                }

 

                

            }

 

            

                            

            return;

            

           

 

        }

 

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




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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-winforms-list/attachments/20070912/60d687c4/attachment.html 


More information about the Mono-winforms-list mailing list