Graphics 类用于winform绘画工具类,就像一个大集合工具箱,可以画各种内容,可以画椭圆,可以画文字,可以将加载的图片渲染过来。
//绘制的地方
<span style="white-space:pre"> </span>private void button1_Click(object sender, EventArgs e)
{
_isPass = true;
ShowImage();
}
<span style="white-space:pre"> </span>//Paint事件注册。最小化等操作之后由于系统重绘,会覆盖程序中的绘画记录
private void Form1_Paint(object sender, PaintEventArgs e)
{
ShowImage();
}
<span style="white-space:pre"> </span>//绘制方法
private void ShowImage()
{
if (_isPass)
{
System.Drawing.Graphics graphics = this.CreateGraphics();
graphics.DrawImage(new Bitmap(@"C:\Users\murry\Desktop\2015-03-23_094104.png"), new Point(100, 100));
graphics.DrawString("Pass", new Font("宋体", 52), Brushes.Red, new PointF(100, 100));
graphics.DrawEllipse(Pens.Red, new Rectangle(100, 50, 400, 200));
}
}