110,537
社区成员
发帖
与我相关
我的任务
分享
//背景图片拆分
private static Bitmap tl = Properties.Resources.Top_Left;
private static Bitmap tm = Properties.Resources.Top_Middle;
private static Bitmap tr = Properties.Resources.Top_Right;
private static Bitmap ml = Properties.Resources.Middle_Left;
private static Bitmap mm = Properties.Resources.Middle_Content;
private static Bitmap mr = Properties.Resources.Middle_Right;
private static Bitmap bl = Properties.Resources.Bottom_Left;
private static Bitmap bm = Properties.Resources.Bottom_Middle;
private static Bitmap br = Properties.Resources.Bottom_Right;
//重绘窗体背景
private void FormPaint(object sender, System.Windows.Forms.PaintEventArgs e)
{
//重绘左上角
e.Graphics.DrawImage(tl, 0, 0, tl.Width, tl.Height);
//重绘上方中间
TextureBrush brush = new TextureBrush(tm, new Rectangle(0, 0, tm.Width, tm.Height));
e.Graphics.FillRectangle(brush, tl.Width, 0, Width - tl.Width - tr.Width, tm.Height);
//重绘右上角
e.Graphics.DrawImage(tr, Width - tr.Width, 0, tr.Width, tr.Height);
//重绘左边框
brush = new TextureBrush(ml);
e.Graphics.FillRectangle(brush, 0, tl.Height, ml.Width, Height - tl.Height - bl.Height);
//重绘中间背景
brush = new TextureBrush(mm);
e.Graphics.FillRectangle(brush, ml.Width, tl.Height, Width - ml.Width - mr.Width, Height - tl.Height - bl.Height);
//重绘右边框
brush = new TextureBrush(mr);
brush.TranslateTransform(Width - mr.Width, tr.Height);//把偏移量补偿回来
e.Graphics.FillRectangle(brush, Width - mr.Width, tl.Height, mr.Width, Height - tr.Height - br.Height);
//重绘左下角
e.Graphics.DrawImage(bl, 0, Height - bl.Height, bl.Width, bl.Height);
//重绘下方中间
brush = new TextureBrush(bm);
brush.TranslateTransform(bl.Width, Height - bm.Height);//把偏移量补偿回来
e.Graphics.FillRectangle(brush, bl.Width, Height - bm.Height, Width - bl.Width - br.Width, bm.Height);
//重绘右下角
e.Graphics.DrawImage(br, Width - br.Width, Height - br.Height, br.Width, br.Height);
}