注册 登录
编程论坛 ASP.NET技术论坛

如何上传用户头像

yan821216 发布于 2012-04-12 17:09, 494 次点击
如何点击一个按钮,弹出选择文件对话框,选择图片后自动上传并显示在image控件中?
1 回复
#2
Issac_abc2012-04-17 10:52
用户一个pictureBox,button,openFileDialog。      
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!");
            }
        }
1