其实很简单首先添加背景图片到所在工程,设置为嵌入式资源。接着获取嵌入式图片资源,覆写OnPaint绘制背景。
private Image bgImage;
public FormBase()
{
bgImage= new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("CMclient.Image.Img_BackGround.gif"));
}
//绘制背景
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
e.Graphics.DrawImage(bgImage, this.ClientRectangle, new Rectangle(0, 0, this.bgImage.Width, this.bgImage.Height), GraphicsUnit.Pixel);
}
private Image bgImage;
public FormBase()
{
bgImage= new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("CMclient.Image.Img_BackGround.gif"));
}
//绘制背景
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
e.Graphics.DrawImage(bgImage, this.ClientRectangle, new Rectangle(0, 0, this.bgImage.Width, this.bgImage.Height), GraphicsUnit.Pixel);
}

浙公网安备 33010602011771号