我有具有下一个结构的 WFA:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.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 openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = System.Environment.CurrentDirectory;
openFileDialog1.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。