机房合作—单击图片修改图片

点击picture,弹出文件框,选中文件,更换图片。 

        //添加图片 
        private string pathname = string.Empty;            //定义路径名变量 
        private void pictureBoxFood_Click(object sender, EventArgs e)
        {
            //打开方法
            OpenFileDialog file = new OpenFileDialog();
            file.InitialDirectory = ".";
            file.Filter = "所有文件(*.*)|*.*";
            file.ShowDialog();
            if (file.FileName != string.Empty)
            {
                try
                {
                    pathname = file.FileName;   //获得文件的绝对路径
                    this.pictureBoxFood.Load(pathname);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
    }
发布了96 篇原创文章 · 获赞 14 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/Ciel_Y/article/details/100085344