c# picturebox如何动态添加图片

2024-12-12 13:25:31
推荐回答(2个)
回答1:

pictureBox1.Image   =   Image.FromFile("d:\\test.jpg"); 

代码就是这样,不知为什么你的不行

private void button1_Click(object sender, EventArgs e)

{

     pictureBox1.Image = Image.FromFile("D:\\chart.png");

}

回答2:

try
{
openFileDialog1.Filter = "JPEG Files (*.jpg)|*.jpg|PNG Files (*.png)|*.png|BMP Files (*.bmp)|*.bmp|All files (*.*)|*.*";
openFileDialog1.FilterIndex = 1;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
pictureBoxPhoto.Load(openFileDialog1.FileName);
}

}
catch
{
MessageBox.Show("图片加载失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}我就这么用的 没问题