【问题标题】:User Control in a winformwinform中的用户控制
【发布时间】:2011-07-07 14:31:50
【问题描述】:

我在 winform 上的 panel1 和 panel2 内有 2 个用户控件,并且表单有下一页 |上一页和关闭按钮。关闭隐藏了winform,我想将用户控件输入的数据保存到一个对象中,以后可以使用该对象将其保存到弹出表单后面的另一个表单上的数据库中。因此 MainForm 打开一个带有 2 个用户控件的表单。我正在尝试将数据保存到一个像这样关闭的对象:

private void btnClose_Click(object sender, EventArgs e)
    {
        UC1 ui1 = new UC1();
        UC2 ui2 = new UC2();
        ui1.SetPage1();
        ui2.SetPage2();

        this.Close();
    }

在用户控件 1 中我有 SetPage1,用户控件 2 有 SetPage2,看起来像:

public void SetPage1()
    {
        UIModel1 uiModel1 = new UIModel1();
        uiModel1.StoppedDate = txtStoppedDate.Text;
        uiModel1.StoppedTime = txtStoppedTime.Text;
        uiModel1.ArrivedNo = txtArrivedNo.Text;
        //etc

这不起作用,我不确定为什么不起作用。我在 txtArrivedNo.Text 的 SetPage1 中放置了一个 MessageBox,它是空的。任何帮助,将不胜感激。

【问题讨论】:

    标签: c# winforms user-controls


    【解决方案1】:

    我假设 UIModel1 是一个模型来存储控制数据。您在 SetPage1 函数中本地创建它,这是错误的。您需要将此模型作为 MainForm 类的成员并将其传递给 SetPage1。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-30
      • 1970-01-01
      • 2020-06-07
      相关资源
      最近更新 更多