private void Timer_Tick(object sender, EventArgs e)
 {
     try
     {
         if (BoundScreen != null)
         {
             BoundScreen.ActionFlush();
         }
     }
     finally
     {
         timer.Start();
     }
 }
        private void buildBuffer()
        {
            var tSize = this.Size;

            if (tSize.Height < 1)
            {
                return;
            }
            if (TerminalFont == null)
            {
                return;
            }

            var tmpG = this.CreateGraphics();

            terminalCanvasBitmap = new Bitmap(tSize.Width, tSize.Height, tmpG);

            terminalCanvasBitmapGraphic = Graphics.FromImage((Image)terminalCanvasBitmap);;
            var charS = terminalCanvasBitmapGraphic.MeasureString("M", TerminalFont);

            charWidth  = Convert.ToInt32(charS.Width + .5) - 6; // This is HACK!  Need to figure out how to deal with font margins
            charHeight = Convert.ToInt32(charS.Height + .5);
            charSize   = new Size(charWidth, charHeight);

            termWidth  = tSize.Width / charWidth;
            termHeight = tSize.Height / charHeight;

            terminalRectangle = new Rectangle(new Point(0, 0), new Size(termWidth * charWidth, termHeight * charHeight));

            if (BoundScreen.Width != termWidth ||
                BoundScreen.Height != termHeight)
            {
                OnTerminalSizeChanged?.Invoke(termWidth, termHeight);    // Need to resize the ansi-decoder/vt100 BoundScreen is attached to
                BoundScreen.ReSize(termWidth, termHeight);
            }

            BoundScreen.DoRefresh(false);
        }
        protected override void OnPaint(PaintEventArgs pe)
        {
            // Dump our frame buffer bitmap to the screen (double-buffered hopefully)

            if (terminalCanvasBitmap != null)
            {
                pe.Graphics.DrawImage((Image)terminalCanvasBitmap, 0, 0);
            }

            // Paint the cursor (if any)
            if (!cursorIsVisible)
            {
                return;
            }

            // Flashing
            if (!cursorOn)
            {
                return;
            }

            // For now, we just draw the character inverted

            var glyph = BoundScreen.GetGlyph(cursorCurrent.X, cursorCurrent.Y);

            glyph.Invert();

            var glyphMap = getGlyph(glyph.Attributes.BackgroundColor,
                                    glyph.Attributes.ForegroundColor,
                                    glyph.Attributes.Elements,
                                    glyph.Char);

            var cursorRect = new Rectangle(new Point(cursorCurrent.X * charWidth, cursorCurrent.Y * charHeight), charSize);

            pe.Graphics.DrawImage((Image)glyphMap, cursorRect);

            base.OnPaint(pe);
        }