我想创建一个 Windows 窗体,它从文件中获取图像并显示在 c# 中的图片框中我在键入 image.FromFile 时遇到问题,“=”后 FromFile 得到红色下划线,就好像它不包含在库中一样。
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Linq;
7 using System.Text;
8 using System.Windows.Forms;
9 using System.IO;
10
11 namespace demo2
12 {
13 public partial class Image : Form
14 {
15 public Image()
16 {
17 InitializeComponent();
18 }
19
20
21
22 private void button1_Click(object sender, EventArgs e)
23 {
24 OpenFileDialog ofd = new OpenFileDialog();
25 ofd.Filter = "image files|*.png;*.jpg;*.gif";
26 DialogResult dr = ofd.ShowDialog();
27
28 if (dr == DialogResult.Cancel)
29 return;
30
31 pictureBox1.Image = Image.FromFile(ofd.FileName);
32 textBox1.Text = ofd.FileName;
33 }
34
35 }
36 }