private void Timer_Tick(object sender, EventArgs e)
{
offScreenGraphics.FillRectangle(Brushes.Black, new RectangleF(0, 0, offsreenBuffer.Width, offsreenBuffer.Height));
for (int y = 0; y < buffer.Height-1; y++)
{
for (int x = 0; x < buffer.Width; x++)
{
var pixel = buffer.GetPixel(x, y);
ConsoleCharacter c = pixel.Value.HasValue ? pixel.Value.Value : new ConsoleCharacter(' ',this.ForegroundColor, this.BackgroundColor);
var fg = (Color)typeof(Color).GetProperty(c.ForegroundColor.ToString(), System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public).GetValue(null);
var bg = (Color)typeof(Color).GetProperty(c.BackgroundColor.ToString(), System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public).GetValue(null);
float imgX = x * charSize.Width;
float imgY = y * charSize.Height;
offScreenGraphics.FillRectangle(new SolidBrush(bg), imgX, imgY, charSize.Width, charSize.Height);
offScreenGraphics.DrawString(c.ToString(), Font, new SolidBrush(fg), new PointF(imgX, imgY));
}
}
var tempImg = onScreenBuffer;
var tempGraphics = onScreenGraphics;
onScreenBuffer = offsreenBuffer;
onScreenGraphics = offScreenGraphics;
offsreenBuffer = tempImg;
offScreenGraphics = tempGraphics;
this.Invalidate();
}