Double buffer with Bitmap
using System;
using System.Drawing;
using System.Windows.Forms;
public class Form1 : Form {
Pen p;
SolidBrush b, bT = new SolidBrush(Color.Black);
string path = "5.bmp";
Image im;
Font f;
public Form1() {
Color cP = Color.Gray;
Color cB = Color.LightGray;
p = new Pen(cP, 6);
b = new SolidBrush(cB);
im = Image.FromFile(path);
f = new Font(new FontFamily("Times New Roman"), 10);
}
static void Main() {
Application.Run(new Form1());
}
protected override void OnPaint(PaintEventArgs pea) {
Sketch();
//SketchDBuf();
}
private void Sketch() {
Graphics g = Graphics.FromHwnd(this.Handle);
g.FillRectangle(b, 4, 4, 260, 220);
g.DrawRectangle(p, 4, 4, 260, 220);
g.DrawImage(im, 33, 35, 200, 145);
g.DrawString("AAAAAA", f, bT, 180, 190);
g.Dispose();
}
private void SketchDBuf() {
int hh = 3, w = 260, h = 220;
Graphics g;
Bitmap bm = new Bitmap(w + 2 * hh, h + 2 * hh);
g = Graphics.FromImage(bm);
g.FillRectangle(b, hh, hh, w, h);
g.DrawRectangle(new Pen(Color.Gray, 2 * hh), hh, hh, w, h);
g.DrawImage(im, hh + 30, hh + 32, 200, 145);
g.DrawString("Text", f, bT, 180, 190);
g = Graphics.FromHwnd(this.Handle);
g.DrawImage(bm, 1, 1);
g.Dispose();
}
}
Related examples in the same category