【发布时间】:2021-11-26 00:09:22
【问题描述】:
我已经制作了一个 WindowsForms 程序:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace FormChooseFolder
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog
{
InitialDirectory = @"C:\",
Title = "Browse Text Files",
CheckFileExists = true,
};
this.openFileDialog1.Multiselect = true;
this.openFileDialog1.Title = "Select Files";
DialogResult dr = this.openFileDialog1.ShowDialog();
if (dr == System.Windows.Forms.DialogResult.OK)
{
TextWriter txt = new StreamWriter("C:\\test.txt");
txt.Write(dr);
txt.Close();
}
}
}
}
应该将所选文件的路径写入test.txt,但它会写入OK。
有什么办法可以让它像C:\Pictures\banana.png一样显示所选文件的路径?
【问题讨论】: