Hi,

I am developing a simple applications using Thread
class to change the color of the square (Lab
assignment). Everything is working properly, except I
have to drag or cls /opn the windows in linux to fix
theThread and the only solutions to produce the color
change.

Well, OnPaint is only called on demand, and not when
a field like "c" suddenly changed ;-)

If you want to cycle the colors, then you have
to force a redraw using form's Refresh () method.

To perform the refresh from another thread, you
probably need to use form's Invoke method, because
UI components usually have a thread affinity.

Rob



I think it has something todo with the X11 rendering
in Linux. Are there any solutions to this problems?



here is my code: (This code should be working in MS
Windows)
[code]
using System;
using System.Windows.Forms;
using System.Threading;
using System.Drawing;

public class ColoredBoxes : Form
{
        private Color c;
        public ColoredBoxes()
        {
                Thread t = new Thread(new ThreadStart(Run));
                t.Start();
        }
        
        protected override void OnPaint(PaintEventArgs e)
        {
                Graphics g = e.Graphics;
                Pen blue = new Pen(c, 3);                               
                g.DrawRectangle(blue, 100,100,30,30);
                base.OnPaint(e);
        }

        public void Run()
        {
                Random r = new Random();
                while(true)
                {
                        c = Color.FromArgb(r.Next(256), r.Next(256),
r.Next(256));
                        Thread.Sleep(200);
                }
        }

}

public class Test{
        public static void Main()
        {
                Application.Run(new ColoredBoxes());
        }
}
[/code]


Thank you for all your help guys



--

Harry Tanama
Programmer/Developer
.NET / JAVA
Powerd by GNU/LiNUX

"Let Christ be glorify in our words and actions."

"Jesus Christ save the entire human race from sins & GNU/Linux save human from high 
cost software applications."


                
__________________________________ Yahoo! Music Unlimited Access over 1 million songs. Try it free.
http://music.yahoo.com/unlimited/

_______________________________________________
Mono-devel-list mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/mono-devel-list

Reply via email to