【问题标题】:Showing the values when form loaded加载表单时显示值
【发布时间】:2010-07-31 06:49:47
【问题描述】:

大家好,我有一个带有树视图控件的主窗体,每个节点下显示一组文件。如果我将鼠标悬停在该节点上,我将使用以下代码读取文本文件中存在的值

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

但我无法显示这些值,请提供任何帮助..

【问题讨论】:

  • 任何人请帮助我。此时我被击中了

标签: c# winforms desktop-application


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    通过以下方式得到答案

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

    【讨论】:

      猜你喜欢
      • 2019-06-01
      • 1970-01-01
      • 2019-05-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-01
      相关资源
      最近更新 更多