c# 怎样打开一个文件显示在窗口,如打开图片并在form中显示,不是folderBrowserDialog,这是打开文件夹的
2个回答
展开全部
用OpenFileDialog
private void button1_Click(object sender, EventArgs e)
{
this.openFileDialog1.Filter = "BMP|*.bmp|GIF|*.gif|PNG|*.png";
if (this.openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
this.pictureBox1.Image = new Bitmap(this.openFileDialog1.FileName);
}
}
private void button1_Click(object sender, EventArgs e)
{
this.openFileDialog1.Filter = "BMP|*.bmp|GIF|*.gif|PNG|*.png";
if (this.openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
this.pictureBox1.Image = new Bitmap(this.openFileDialog1.FileName);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询