阅读表单加载事件中的嵌入式TXT文件。
动态设置变量。
string f1 = "AppName.File1.Ext";
string f2 = "AppName.File2.Ext";
string f3 = "AppName.File3.Ext";
呼叫尝试接球。
try 
{
     IncludeText(f1,f2,f3); 
     /// Pass the Resources Dynamically 
     /// through the call stack.
}
catch (Exception Ex)
{
     MessageBox.Show(Ex.Message);  
     /// Error for if the Stream is Null.
}
为IncludeText()创建空对象,Visual Studio为您完成此操作。单击灯泡以自动生成代码块。
将以下内容放入生成的代码块中
资源1
var assembly = Assembly.GetExecutingAssembly();
using (Stream stream = assembly.GetManifestResourceStream(file1))
using (StreamReader reader = new StreamReader(stream))
{
string result1 = reader.ReadToEnd();
richTextBox1.AppendText(result1 + Environment.NewLine + Environment.NewLine );
}
资源2
var assembly = Assembly.GetExecutingAssembly();
using (Stream stream = assembly.GetManifestResourceStream(file2))
using (StreamReader reader = new StreamReader(stream))
{
string result2 = reader.ReadToEnd();
richTextBox1.AppendText(
result2 + Environment.NewLine + 
Environment.NewLine );
}
资源3
var assembly = Assembly.GetExecutingAssembly();
using (Stream stream = assembly.GetManifestResourceStream(file3))
using (StreamReader reader = new StreamReader(stream))
{
    string result3 = reader.ReadToEnd();
    richTextBox1.AppendText(result3);
}
如果您希望将返回的变量发送到其他地方,只需调用另一个函数并...
using (StreamReader reader = new StreamReader(stream))
{
    string result3 = reader.ReadToEnd();
    ///richTextBox1.AppendText(result3);
    string extVar = result3;
    /// another try catch here.
   try {
   SendVariableToLocation(extVar)
   {
         //// Put Code Here.
   }
       }
  catch (Exception ex)
  {
    Messagebox.Show(ex.Message);
  }
}
这是通过一种在单个富文本框中组合多个txt文件并读取其嵌入数据的方法实现的。这是我对代码示例的预期效果。
               
              
Environment.SpecialFolder获取桌面文件夹。您需要记住,资源将根据其在项目中的路径进行命名空间,因此其名称可能不是justfile1.txt。