musketball's picture

Picturebox paint handler causing problems.

I have a form with a GLControl, a few buttons, and a picturebox. Below are the Click and Paint handlers for the picturebox. These routines stop the GLCOntrol from updating. If I comment out the calls to load the images into the picturebox, then all is fine again. Why would loading images into the picturebox break the GLControl paint events?

       private void pictureBox1_Paint(object sender, PaintEventArgs e)
        {
           // return;
 
            using (Font myFont = new Font("Arial", 9))
            {
                if (!clicked)
                {
                    timer1.Enabled = false;
                    e.Graphics.DrawString("Start", myFont, Brushes.White, new Point(2, 2));
                    pictureBox1.Image = new Bitmap(@"C:\DEVEL\projects\tktest\tktest\bin\Debug\Unlit.png");
                }
                else
                {
                    timer1.Enabled = true;
                    e.Graphics.DrawString("Stop", myFont, Brushes.White, new Point(2, 2));
                    pictureBox1.Image = new Bitmap(@"C:\DEVEL\projects\tktest\tktest\bin\Debug\Lit.png");
                }
            }
        }
 
        private void pictureBox1_Click(object sender, EventArgs e)
        {
            clicked ^= true;
            pictureBox1.Invalidate();
        }

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
musketball's picture

Well, that was easy. I had a little bit of a brain fart there. Loading the image INSIDE the paint handler caused what? Another paint event, so nice little endless loop. I load the picturebox image from within the click event handler and problem solved. Duh.