Learn from 0 c#06--multi-form common objects

Source: Internet
Author: User
The previous article introduced the way a delegate event was implemented to invoke a control of a parent form by a subform. This article will implement a common entity object in the same way as parameter passing.

The code used in this article is also modified on the basis of the previous article.

1. Parent form

Innobert the pooled entity object as a parameter to the subform constructor. The code follows the "Modify this line" section.

if (subformppgtx[i] = = NULL | | subformppgtx[i]. isdisposed)                    {                        Subformppgtx[i] = new SUBFORMPPG (Innobert, I);//Modify this line                        Subformppgtx[i]. Text = Formtitle;                        Subformppgtx[i]. Name = FormName;                        Subformppgtx[i]. Tag = i;                        Subformppgtx[i]. Sendtoparent + = new Subformppg.sendfun (recvinfo);                        Subformppgtx[i]. Show (this);                    }                    else                    {                        subformppgtx[i]. WindowState = Formwindowstate.normal;                        Subformppgtx[i]. Activate ();                    }

2. Subform

You first define a class field and then modify the subform's constructor, adding parameters to receive the entity objects that the parent form passes. This makes it possible to invoke the entity object Innobert in the subform.

Innolightbert Innolightbert;bool formstatus = false;private int id;public delegate void Sendfun (int number);p Ublic event S Endfun sendtoparent;public subformppg (innolightbert innobert, int ID) {    InitializeComponent ();    This.innolightbert = innobert;//Receive object    this.id = ID;}

3. Application

The subform invokes the properties of the shared entity object.

private void Subformppg_load (object sender, EventArgs e) {this    . Getppgsetting (this.id);} private void getppgsetting (int channel) {    try    {        switch (channel)        {case            0:                This.comboBoxSwing.SelectedIndex = (int) innolightbert.tx1_swing;                break;            Case 1:                this.comboBoxSwing.SelectedIndex = (int) innolightbert.tx2_swing;                break;            Case 2:                this.comboBoxSwing.SelectedIndex = (int) innolightbert.tx3_swing;                break;            Case 3:                this.comboBoxSwing.SelectedIndex = (int) innolightbert.tx4_swing;                break;             Default:                 return;        }    }    catch (Exception ex)    {        MessageBox.Show (ex. Message);}    }

The above is from 0 self-learning c#06--multi-form common object content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • Related Article

    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.