我正在尝试打开文件对话框,然后将文件夹内的文件打开到不同的富文本框中?但我不确定还需要添加什么?你能帮个忙吗?
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
richTextBox1.Text = File.ReadAllText(openFileDialog1.FileName);
tabPage1.Text = openFileDialog1.SafeFileName;
}
如果要允许用户选择一个文件夹,然后打开该文件夹中存在的前5个文件,请在不同的richtextbox中打开每个文件,则不需要OpenFileDialog
,但FolderBrowserDialog
// First prepare two list with the richtextboxes and the tabpages
List<RichTextBox> myBoxes = new List<RichTextBox>()
{ richTextBox1, richTextBox2, richTextBox3, richTextBox4, richTextBox5 };
List<TabPage> myPages = new List<TabPage>()
{ tabPage1, tabPage2, tabPage3, tabPage4, tabPage5};
// Now open the folderbrowser dialog
// (see link above for some of its properties)
FolderBrowserDialog fbd = new FolderBrowserDialog();
if(fbd.ShowDialog() == DialogResult.OK)
{
int i = 0;
foreach(string file in Directory.GetFiles(fbd.SelectedPath))
{
myBoxes[i].Text = File.ReadAllText(file);
myPages[i].Text = Path.GetFileName(file);
i++;
// Added a warning if the folder contains more than 5 files
if(i >= 5)
{
MessageBox.Show("Too many files in folder, only 5 loaded");
break;
}
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句