0

我有具有下一个结构的 WFA:

using System;
using System.Collections.Generic;
using System.­­­­ComponentModel;
using Sy­­­­stem.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using WindowsFormsApplication1.Properties;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        List<string> urls = new List<string>();
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            openFileDialog1.InitialDirectory = System.Environment.CurrentDirectory;
            openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                urls.Clear();
                foreach (string url in File.ReadAllLines(openFileDialog1.FileName))
                    urls.Add(url);
                label2.Text = urls.Count.ToString();
            }
        }

        List<string> links = new List<string>();
        private void open2FileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog open­­­­FileDialog1 = new OpenFileDialog();
            openFileDialog1.InitialDirectory = System.Environment.CurrentDirectory;
            openFile­­­­Dialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                links.Clear();
                foreach (string link in File.ReadAllLines(openFileDialog1.FileName))
                    links.Add(link);
                label4.Text = links.Count.ToString();
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            Settings.Default.Save();
        }
    }
}

设计画面:

http://screenshotuploader.com/i/01/k0tpbijza.png

我需要将在 openFileDialog 中打开的文件路径保存到propeties.settings。

4

1 回答 1

0

您需要将 设置RestoreDirectory为 true 以及InitialDirectory属性。

有关该主题的更多信息:设置 SaveFileDialog 的初始目录?

于 2012-12-20T11:41:17.177 回答