如何上传用户头像
如何点击一个按钮,弹出选择文件对话框,选择图片后自动上传并显示在image控件中?
this.pictureBox1.Image = img;
this.BackgroundImage = img;
这两行都可以显示图像。
程序代码:
private void button1_Click(object sender, EventArgs e) { if (this.openFileDialog1.ShowDialog() != DialogResult.OK) return; try { Image img = Image.FromFile(this.openFileDialog1.FileName); this.pictureBox1.Image = img; this.BackgroundImage = img; } catch (System.Exception ex) { MessageBox.Show("ERROR!"); } }