User Control in a winform
I have 2 user controls inside panel1 and panel2 on a winform and the form has next page | previous page and close buttons. The close hides the winform and I want to save the user controls inputed data to an object that I can use later to save to a database on another form behind the forms that popup. So MainForm opens a form that opens the form with the 2 user controls. I'm trying to save the data to an object with the close like this:
private void btnClose_Click(object sender, EventArgs e)
{
UC1 ui1 = new UC1();
UC2 ui2 = new UC2();
ui1.SetPage1();
ui2.SetPage2();
this.Close();
}
And in user开发者_如何学Go control 1 i have SetPage1 and user control 2 has SetPage2 that look like:
public void SetPage1()
{
UIModel1 uiModel1 = new UIModel1();
uiModel1.StoppedDate = txtStoppedDate.Text;
uiModel1.StoppedTime = txtStoppedTime.Text;
uiModel1.ArrivedNo = txtArrivedNo.Text;
//etc
This isn't working and I'm not sure why it isn't. I put a MessageBox inside the SetPage1 for the txtArrivedNo.Text and it's empty. Any help would be appreciated.
I assume that UIModel1 is a model to store the control data. You create it locally in SetPage1 function which is wrong. You need to make this model as a member of your MainForm class and pass it to SetPage1.
精彩评论