【发布时间】:2023-04-07 09:19:01
【问题描述】:
我想将我的 TextBox 的值从 Form1 传递到 Form2。
然后出现这条消息。
"Form that is not a top-level form cannot be displayed as a modal dialog box. Remove the form from any parent form before calling showDialog."
这是我的Form1代码:
private void btnAddReceipt_Click(object sender, EventArgs e)
{
this.Hide();
using (var Ticket = new frmCustomerTicket())
{
Ticket.CustomerID = txtCustNo.Text;
ShowDialog();
}
}
这是我在 Form2 中的代码
public string CustomerID { get; set; }
private void frmCustomerTicket_Load(object sender, EventArgs e)
{
txtCustID.Text = CustomerID;
}
【问题讨论】:
-
您是否只是从一个表单发送到另一个表单的一个值。如果它只是一个文本框值,为什么不使用会话变量,如 Session["txtValue"]=txtCustID.Text 和在 Form2 中访问此会话变量。
-
@Gayatri,它听起来像是一个 winforms 应用程序,所以你将无法使用 Session
标签: c# sql-server-2008