使用 C# 加载图像
本文关键字:图像 加载 使用 | 更新日期: 2023-09-27 18:33:25
I 打开图像 我尝试了这种方法,但是当我单击按钮时,窗口没有出现所以我无法加载图像
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog open = new OpenFileDialog();
if (open.ShowDialog() == DialogResult.OK)
{
pictureBox1.ImageLocation = open.FileName;
}
这样做
它将完美工作并显示完整图像。
private void button1_Click_1(object sender, EventArgs e)
{
OpenFileDialog open = new OpenFileDialog();
if (open.ShowDialog() == DialogResult.OK)
{
pictureBox1.ImageLocation = open.FileName;
pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
}
}
OpenfileDialog上有"打开"和"取消"按钮。因此,由于上面没有"确定"按钮,因此"if 条件"将不为真。您应该将其更改为:
Private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog open = new OpenFileDialog();
if (open.ShowDialog() != DialogResult.Cancel)
{
pictureBox1.ImageLocation = open.FileName;
}
}