5
我想创建一个窗体,从文件中获取图像并显示在pictureBox中的c# 我有问题,当我在“=”后输入image.FromFile时,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 }
你可以请编辑我的代码或告诉我哪里必须更改代码。 –
第31行:'pictureBox1.Image = System.Drawing.Image.FromFile(ofd.FileName);' – sasjaq
非常感谢亲爱的工作......非常感谢很多... :-) –