How to pass parameter in windows form from one form to another?


This is how we can pass parameter from one form to another:

Here is form1:
Parent Form (frmParent)

//Write the code on click event
  frmParent frmObj = new frmParent(strUserID, strRole);
  frmObj.ShowDialog();


Here is form2:

Child Form (frmChild)


public partial class frmChild: Form
    {
      private string strUserID = string.Empty;
private string strRole = string.Empty;


        public frmChild(string strUserID, string strRole)
        {
            this. strUserID = strUserID;
            this. strRole = strRole;
            InitializeComponent();
          
            TextBox1.Text = strUserID;
        }
}

Comments