1.初始设置字体与笔
Pen pen = new Pen(Color.FromArgb(220, Color.Green), 5);Font font = new Font("微软雅黑", fontSize, FontStyle.Bold); // 定义字体Brush whiteBrush = new SolidBrush(Color.FromArgb(220, Color.Red)); // 画文字用
2.初始设置图片和Graphics (可循环2-4)
// pic drawBitmap picBitmap = new Bitmap(fi.FullName);Graphics grapPic = Graphics.FromImage(picBitmap);
3.画矩形和文字(可多次画画)
// draw icongrapPic.DrawRectangle(pen, posIcon.X, posIcon.Y, posIcon.Width, posIcon.Height);// draw textstring text = icon.DeviceName;// 下面定义一个矩形区域float rectWidth = text.Length * (fontSize + 10);float rectHeight = fontSize + 10;// 声明矩形域RectangleF textArea = new RectangleF(posIcon.X + posIcon.Width, posIcon.Y, rectWidth, rectHeight);grapPic.DrawString(text, font, whiteBrush, textArea);
4.dispose Graphics 与图片
// dispose picgrapPic.Dispose();picBitmap.Dispose();
5.dispose 笔与字体
pen.Dispose();whiteBrush.Dispose();font.Dispose();