Return values from dialog box

后端 未结 4 1050
不知归路
不知归路 2020-12-21 05:58

how to send and return values in modal dialog form

4条回答
  •  醉话见心
    2020-12-21 06:40

    This is how I would call the dialog box

     var regStoreForm = new RegisterStoreForm(storeID,password);
                if (regStoreForm.ShowDialog(this) == DialogResult.OK)
                {
                    storeID = regStoreForm.StoreId;
                    password = regStoreForm.StorePassword;
                };
                regStoreForm.Dispose();
    

    And this is what the Dialog box looks like

     public partial class RegisterStoreForm : Form
        {
            public int StoreId { get; set; }
            public String StorePassword { get; set; }
    
            public RegisterStoreForm(int storeId,string password)
            {
                InitializeComponent();
                StoreId = storeId;
                StorePassword = password;
                this.textBoxPassword.Text = StorePassword;
                this.textBoxStoreId.Text = StoreId.ToString();
            }
    
            private void OKbutton_Click(object sender, EventArgs e)
            {
                StoreId = Convert.ToInt16(textBoxStoreId.Text);
                StorePassword = textBoxPassword.Text;
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }
    

提交回复
热议问题