[C#] 纯文本查看 复制代码
public static void RenderBackground(Graphics g, Image img, Rectangle rect) {
//填充四个角
g.DrawImage(img, new Rectangle(rect.X, rect.Y, 5, 5),
new Rectangle(0, 0, 5, 5), GraphicsUnit.Pixel);
g.DrawImage(img, new Rectangle(rect.Right - 5, rect.Y, 5, 5),
new Rectangle(img.Width - 5, 0, 5, 5), GraphicsUnit.Pixel);
g.DrawImage(img, new Rectangle(rect.X, rect.Bottom - 5, 5, 5),
new Rectangle(0, img.Height - 5, 5, 5), GraphicsUnit.Pixel);
g.DrawImage(img, new Rectangle(rect.Right - 5, rect.Bottom - 5, 5, 5),
new Rectangle(img.Width - 5, img.Height - 5, 5, 5), GraphicsUnit.Pixel);
//四边
g.DrawImage(img, new Rectangle(rect.X, rect.Y + 5, 5, rect.Height - 10),
new Rectangle(0, 5, 5, img.Height - 10), GraphicsUnit.Pixel);
g.DrawImage(img, new Rectangle(rect.X + 5, rect.Y, rect.Width - 10, 5),
new Rectangle(5, 0, img.Width - 10, 5), GraphicsUnit.Pixel);
g.DrawImage(img, new Rectangle(rect.Right - 5, rect.Y + 5, 5, rect.Height - 10),
new Rectangle(img.Width - 5, 5, 5, img.Height - 10), GraphicsUnit.Pixel);
g.DrawImage(img, new Rectangle(rect.X + 5, rect.Bottom - 5, rect.Width - 10, 5),
new Rectangle(5, img.Height - 5, img.Width - 10, 5), GraphicsUnit.Pixel);
//中间
g.DrawImage(img,
new Rectangle(rect.X + 5, rect.Y + 5, rect.Width - 10, rect.Height - 10),
new Rectangle(5, 5, img.Width - 10, img.Height - 10), GraphicsUnit.Pixel);
}