Today, when I was doing a C # design for a contact management, I encountered this problem, I needed to pass the values in the TextBox in my parent form to the subform and perform the database query operations, and I used the new parent form (). TextBox.Text; To carry out the value transfer, however, there is no egg, after many experiments, found a relatively simple solution:
Parent form:Logout
Subform:Affirm
Parent form text box:tb_logout_username
public partial class Logout : Form
{
Define a static variable to hold the value of a text box in the parent form
public static string tb_logoutname;
Instantiate an event for a subform
private void Btt_logout_click (object sender, EventArgs e)
{
//Gets the value of the text box in the parent form
tb_logoutname = tb_logout_username. Text;
affirm aff = new affirm();
Aff. Show ();
}
}
The next call in the subform can be directly: the parent form. variables
namely:Logout. Tb_logoutname
Summary: This method seems relatively trickery, supposedly should find the method to get the parent form, and then operate on it, for reference only, hope that the same problem you have helped, but also welcome the great God to give a better way.
C # Subform Gets the contents of a control in a parent form