有两种方法,方法一:
1、this.BackgroundImage = Image.FromFile(@"图片路径")
2、this.BackgroundImage = this.imageList1.Images[0]
方法二:
imageList设置图片像素只能是在1-256
C# 窗体背景图片怎么跟随窗体变化而变化
背景图单独存放在其它位置后,当窗口的OnResize事件发生时,
对图片缩放后,作为背景。根据此原理,实现如下:
这里借用了一个pictureBox.不改变它的其它属性,如改变Image属性后,编写如下代码
private void Form2_SizeChanged(object sender, System.EventArgs e){loadBackImage();}
private void loadBackImage(){Bitmap bit = new Bitmap(this.Width,this.Height);
Graphics g = Graphics.FromImage(bit);
g.DrawImage(this.pictureBox1.Image,newRectangle(0,0,bit.Width,bit.Height),0,0,this.pictureBox1.Image.Width,this.pictureBox1.Image.Height,GraphicsUnit.Pixel);
this.BackgroundImage = bit;
g.Dispose();}private void Form2_Load(object sender, System.EventArgs e)loadBackImage();}