OpenFileDialog file=new OpenFileDialog();
if(file.ShowDialog()==DialogResult.Ok){
panel.BackgroundImage = ((System.Drawing.Image)(resources.GetObject(file.FileName)));
}
if(file.ShowDialog()==DialogResult.Ok){
panel.BackgroundImage = ((System.Drawing.Image)(resources.GetObject(file.FileName)));
}
用的是嵌入的资源,即背景图已作为托管的资源嵌入exe中,名字叫"panel.BackgroundImage";如果想自己指定路径,用panel.BackgroundImage = new Bitmap(path);即可
string path;为图像路径.