示例#1
0
        // Paint control
        protected override void OnPaint(PaintEventArgs pe)
        {
            if ((needSizeUpdate) || (firstFrame))
            {
                UpdatePosition();
                needSizeUpdate = false;
            }

            // lock
            Monitor.Enter(this);

            Graphics  g   = pe.Graphics;
            Rectangle rc  = this.ClientRectangle;
            Pen       pen = new Pen(Color.Black, 1);

            // draw rectangle
            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 - 2, rc.Height - 2);
                    firstFrame = false;
                }
                else
                {
                    // Create font and brush
                    Font       drawFont  = new Font("Arial", 12);
                    SolidBrush drawBrush = new SolidBrush(Color.White);

                    g.DrawString("Connecting ...", drawFont, drawBrush, new PointF(5, 5));

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

                camera.Unlock();
            }

            pen.Dispose();

            // unlock
            Monitor.Exit(this);

            base.OnPaint(pe);
        }