Esempio n. 1
0
        private void CameraPlay_Paint(object sender, PaintEventArgs pe)
        {
            if ((needSizeUpdate) || (firstFrame))
            {
                UpdatePosition();
                needSizeUpdate = false;
            }


            Monitor.Enter(pnVideo);
            Graphics  g  = pnVideo.CreateGraphics();
            Rectangle rc = this.ClientRectangle;
            Pen       pen;

            if (ClickMe)
            {
                pen = new Pen(Color.Green, 3);
                g.DrawRectangle(pen, rc.X, rc.Y, rc.Width - 2, rc.Height - 2);
            }
            else
            {
                pen = new Pen(Color.Black, 1);
                g.DrawRectangle(pen, rc.X, rc.Y, rc.Width - 1, rc.Height - 1);
            }

            if (camera != null)
            {
                camera.Lock();

                // draw frame
                if (camera.LastFrame != null)
                {
                    g.DrawImage(camera.LastFrame, rc.X + 1, rc.Y + 1, rc.Width - 3, rc.Height - 3);
                    firstFrame = false;
                }
                else
                {
                    // Create font and brush
                    Font       drawFont  = new Font("Arial", 12);
                    SolidBrush drawBrush = new SolidBrush(Color.White);

                    g.DrawString("连接中 ...", drawFont, drawBrush, new PointF(5, 5));

                    drawBrush.Dispose();
                    drawFont.Dispose();
                }

                camera.Unlock();
            }

            pen.Dispose();

            // unlock
            Monitor.Exit(pnVideo);

            base.OnPaint(pe);
        }