1、准备一张JPG格式的图片作为背景图,图片尺寸大小要与窗体大小相同
2、在代码中添加背景图片的调用,注意这里的图片的路径需要使用绝对路径。
public Form1()
{
InitializeComponent();
this.BackgroundImage = Image.FromFile(@"D://桌面/VS项目/study/study/C#入门/jpg/1.jpg");//文件路径
this.BackgroundImageLayout = ImageLayout.Stretch;//自动延展
}
1.绝对路径:
this.pictureBox2.Image=Image.FromFile("D:\\1.jpg");
2.相对路径:
Application.StartupPath;
可以得到程序根目录
string picPath=Application.StartupPath+"\\1.gif";
3.获得网络图片的路径
this.pictureBox2.Image= Image.FromStream(System.Net.WebRequest.Create(http://www.xyhhxx.com/images/logo/logo.gif).GetResponse().GetResponseStream());