public Frm_Main()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//设置文件的类型
openFileDialog1.Filter = "*.jpg,*.jpeg,*.bmp,*.gif,*.ico,*.png,*.tif,*.wmf|*.jpg;*.jpeg;*.bmp;*.gif;*.ico;*.png;*.tif;*.wmf";
openFileDialog1.ShowDialog(); //打开文件对话框
//根据文件的路径和名称实例化Image类
Image myImage = System.Drawing.Image.FromFile(openFileDialog1.FileName);
pictureBox1.Image = myImage;//显示图片
pictureBox1.Height = myImage.Height; //设置控件的高度
pictureBox1.Width = myImage.Width; //设置控件的宽度
}
下一篇 鼠标拖拽图像实例