C# 显示加载表单时的值
Hi all i have main form带有一个treeview控件,每个节点下都显示一组文件。如果将鼠标放在该节点上,我将使用以下代码读取文本文件中的值C# 显示加载表单时的值,c#,winforms,desktop-application,C#,Winforms,Desktop Application,Hi all i have main form带有一个treeview控件,每个节点下都显示一组文件。如果将鼠标放在该节点上,我将使用以下代码读取文本文件中的值 private void treeViewACH_NodeMouseHover(object sender, TreeNodeMouseHoverEventArgs e) { string strFile = string.Empty; System.Text.StringBuilder mes
private void treeViewACH_NodeMouseHover(object sender, TreeNodeMouseHoverEventArgs e)
{
string strFile = string.Empty;
System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder();
messageBoxCS.AppendFormat(" {0}", e.Node);
strFile = messageBoxCS.ToString().Substring(11);
strFilePath = Directory.GetCurrentDirectory();
strFilePath = Directory.GetParent(strFilePath).ToString();
strFilePath = Directory.GetParent(strFilePath).ToString();
strFilePath = strFilePath + "\\ACH" + "\\" + strFile;
if ((File.Exists(strFilePath)))
{
StreamReader sr = new StreamReader(strFilePath);
StringComparison compareType = StringComparison.InvariantCultureIgnoreCase;
string fileName = Path.GetFileNameWithoutExtension(strFilePath);
string extension = Path.GetExtension(strFilePath);
if (fileName.StartsWith("FileHeader", compareType)
&& extension.Equals(".txt", compareType))
{
string s = sr.ReadToEnd();
StringBuilder sb = new StringBuilder();
//sb.Append("RecordTypeCode\tPriorityCode");
//sb.Append("\n");
//sb.Append("--------------------------------------------------");
//sb.Append("\n");
objFile.ReferenceTypeCode = s.Substring(0, 1);
sb.Append(objFile.ReferenceTypeCode);
string PriorCode = s.Substring(1, 2);
sb.Append(PriorCode);
objFile.getValues(sb.ToString());
frmTemp frmtemp = new frmTemp();
frmtemp.Show();
}
}
现在我想把每个文本框中的值放到表单加载中。但由于它是一种不同的形式,我无法从业务层访问这些值
我已经在表单加载中编写了这样的代码
BL.FileHeader objFile = new FileHeader();
private void frmTemp_Load(object sender, EventArgs e)
{
textBox1.Text = objFile.ReferenceTypeCode;
}
但是我无法显示值。请提供任何帮助。为要显示的每个值向
frmTemp
类添加属性。在nodemousehave
处理程序中,在创建表单实例后立即为这些属性赋值。然后,在frmTemp\u Load
处理程序中,将这些属性的值分配给TextBox
控件
frmTemp frmtmp = new frmTemp(strFileHeader);
frmtmp.Show();
public frmTemp(string str)
{
InitializeComponent();
if (str.StartsWith("1"))
{
this.textBox1.Text = str.Substring(0, 1);
}
else if (str.StartsWith("5"))
{
this.textBox1.Text = str.Substring(0, 1);
this.textBox2.Text = str.Substring(4, 16);
}
}
任何人请帮助我。我在这一点上被吓坏了