C # Subform Gets the contents of a control in a parent form

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.