private Bitmap _bitmap;
private void FormTest_MouseMove(object sender, MouseEventArgs e)
{
this.label1.Text = e.Location.ToString();
Color color = _bitmap.GetPixel(e.Location.X, e.Location.Y);
this.label2.Text = color.ToString();
this.label3.Text = this.Width + " " + this.Height + "\n" + this.ClientSize.Width + " " + this.ClientSize.Height;
}
private void FormTest_Load(object sender, EventArgs e)
{
_bitmap = new Bitmap(this.Width, this.Height);
using (var gr = Graphics.FromImage(_bitmap))
{
gr.FillRectangle(Brushes.Red, new Rectangle(10, 200, 100, 100));
}
}
private void FormTest_Paint(object sender, PaintEventArgs e)
{
var rect = new Rectangle(0, 0, _bitmap.Width, _bitmap.Height);
e.Graphics.DrawImage(_bitmap, rect, rect, GraphicsUnit.Pixel);
}