(这是关于这个问题的讨论的延续)我有在 C: 驱动器中的特定文件夹中查找的代码。它可以判断该文件夹中的内容,并获取用户选择的内容。但问题是切换到一个新的数据文件夹来获取代码。
运行程序所需的所有代码都保存在 Data 文件夹中,我正在实习的公司希望能够切换 Data 文件夹,以便他们可以更好地展示他们的软件,并让它面向任何他们展示它的人。
所以基本上我的程序需要切换数据文件夹,这样公司才能更好地展示他们的软件。
把我所有的代码贴出来,不多,大家可以看一下。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
string defaultPath = @"C:\Mavro\MavBridge\";
public Form1()
{
InitializeComponent();
dropdown();
}
private void button1_Click(object sender, EventArgs e)
{
//some sort of code to switch directory before close goes here
MessageBox.Show("Data folder has been changed.", "Done");
Application.Exit();
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
string path = comboBox1.SelectedItem.ToString();
defaultPath = path;
}
private void buttonTest_Click_1(object sender, EventArgs e)
{
}
public void dropdown()
{
string[] dispDirectories = Directory.GetDirectories(defaultPath, "Data*");
comboBox1.Items.Clear();
comboBox1.Items.AddRange(dispDirectories);
}
}
}