【问题标题】:How do I set values in existing Forms and return to original form from a new form?如何在现有表单中设置值并从新表单返回原始表单?
【发布时间】:2019-03-15 20:13:59
【问题描述】:

所以我有一个表格 InvCert 我打开表单 GetSomeInfo 的一个实例 在 GetSomeInfo 中,我有文本框等,并希望这些 .Text 值成为原始形式 InvCert 中的值。我假设 Form.stringname = 将允许我这样做,但我的值并没有跨越到原始形式。不知何故,我同时没有错误消息。

'frmInvCert.certType = comboInvLvl.Text;
frmInvCert.thisYear = dateTimeCurrent.Text;
frmInvCert.myFileName = txtInvestor.Text;
frmInvCert.getAdress = txtAddress.Text;
string certType = comboInvLvl.Text;
new frmInvCert().Show();
this.Close();`

然后,这些值被用于方法中。但是程序并没有等到我们回到原来的表格来填写这些值。它只会创建空白。

this.Hide();
                new frmGetSomeInfo().Show();
                //creates even if values not filled!
                //May need to retun to original instead somehow or find out how to put these mthods into the new form
                //initialize checkboxes after with paths connected
                //initialize tab pages with paths connected
                if(thisYear != null && certType != null && myFileName != null)
                {
                    CreateCertificate();
                }
                CreateCertificate();

【问题讨论】:

    标签: c# .net windows forms


    【解决方案1】:

    在这一行:

    new frmInvCert().Show();
    

    您正在打开一个新实例,而不是您设置值的实例。改成这样:

    frmInvCert frm = new frmInvCert();
    frm.certType = comboInvLvl.Text;
    frm.thisYear = dateTimeCurrent.Text;
    frm.myFileName = txtInvestor.Text;
    frm.getAdress = txtAddress.Text;
    frm.Show();
    

    【讨论】:

    • 这似乎仍然不起作用。我正在使用这些值来设置文件的路径名。
    • public void CreateCertificate() { //在文件夹\子文件夹\thisyear Certificates- certType\certificatehere 中创建证书,如果存在则覆盖 ///检查缓冲区整数 不确定那是什么 /// //\\BDCSERVER\SDrive\Files\INVESTORS\Investor Certificates\2018 Certificates\ String basePath =
    • @"C:\Users\Director\Documents\TestCertApp\TestSub\"; String certificateFolder = $"{thisYear} Certificates- {certType}"; String correctFilePath = Path.Combine(basePath, certificateFolder, $" {myFileName}.ppt"); File.Create(正确的文件路径); }
    • 我得到空值而不是包含这些值的路径,因此我的文件夹和子文件夹没有正确的名称,我的 ppt 文件完全无名
    猜你喜欢
    • 2016-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多