怎么在后面的image显示图片visual studio c# 语言来写
1个回答
展开全部
假设页面有按钮BtnShowImage,图片显示控件pbxShow ,BtnShowImage_Click
为BtnShowImage按钮的Click事件 则如下代码可以实现选择图片文件显示图片
private void BtnShowImage_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.InitialDirectory = "c:\\";
openFileDialog.Filter = @"图像文件(JPeg, Gif)|*.jpg;*.jpeg;*.gif;*.bmp;*.png| JPeg 图像文件(*.jpg;*.jpeg)"
+ "|*.jpg;*.jpeg |GIF 图像文件(*.gif)|*.gif |BMP图像文件(*.bmp)|*.bmp|Png图像文件(*.png)"
+ "| *.png ";
openFileDialog.RestoreDirectory = true;
openFileDialog.FilterIndex = 1;
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
var fName = openFileDialog.FileName;
Image img = Image.FromFile(fName);
this.pbxShow.Image = img;
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询