2010-07-31 17 views
0

大家好我有一个树形控件的主窗体,并在每个节点下显示一组文件。如果我有我的鼠标移到节点i将通过使用下面的代码显示表单加载时的值

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; 
    } 

访问值,但我无法显示该值的任何帮助,请..

+0

任何一个请帮我得到了答案。我在这一点被攻击 – Dotnet 2010-07-31 12:13:44

回答

0

由以下

  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); 
     } 
    } 
1

为您要显示的每个值添加属性到您的frmTemp类。在您的NodeMouseHover处理程序中,在创建表单实例之后立即为这些属性赋值。然后,在frmTemp_Load处理程序中,将这些属性的值分配给TextBox控件。

+0

你能否请详细解释一个示例代码 – Dotnet 2010-08-02 07:58:11