在表单上,我有很多richtextboxes。当表单加载时,我想用txt文件中的文本填充richTextBoxes。对于每个richTextBox,我都有一个文本文件,并且该文件的名称与richTextBox名称相同。 我试过这个,但它不工作,因为一个组件没有loadfile函数?获取所有richTextBoxes并加载具有相同名称的文本文件
如何在加载表单时将大量文件加载到不同的richtextBox中?
private void getAllRichTextboxen(string aFileName)
{
foreach(Control item in this.Controls)
{
if (item is GroupBox) //first get the groupboxes, all the richTextBoxes are within a groupBox
{
foreach (Control aControl in item.Controls)
{
if (aControl is RichTextBox) //check if it is a richTextBox
{
if (aControl.Name == aFileName) //if the controle name = the same as the file name then load the file into the RichTextBox
{
aControl.LoadFile(Settings.applicatiePad + Form_Main.QueryMap + "\\" + aFileName + ".agq", RichTextBoxStreamType.PlainText));
//richTextBox1.LoadFile(openFile1.FileName, RichTextBoxStreamType.PlainText);
}
}
}
}
}
}