C# 动态更改imagebox背景图片

       private void pBox_Exit_MouseDown(object sender, MouseEventArgs e)
        {
            PictureBox backgroundPicture = (PictureBox)sender;
            backgroundPicture.Image = (System.Drawing.Image)Resources.ResourceManager.GetObject((string)backgroundPicture.Tag);
           // backgroundPicture.Image = System.Drawing.Image.FromFile(@"E:\vs2010_project\CameraForPC\CameraForPC\images\png2\拍照-2.png");
           
        }

 

1.利用Tag属性保存文件名称
2.动态调用Resources里的图片资源

3.利用一个事件响应所有的imageBox的MouseDown消息

 

 string path = System.IO.Directory.GetCurrentDirectory();//获取当前路径为/bin/.exe/下的文件

你可能感兴趣的:(C# 动态更改imagebox背景图片)