C # Cross-form operations (reference transfer)

Source: Internet
Author: User

Now we will introduce you to the simplest cross-form operation.

The WinForm is a class, and the C # class is a reference type. So we should be able to pass the WinForm class, so we can not perform the operation?

 

Effect description:

There are three forms and the order is

(1) click the button in the first form to bring up the second form and hide the first form.

(2) The third form is displayed from the second form to a certain time.

(3) click the button of the third form to close the third and second forms. The first form is displayed.

 

From1

 

Using System;

Using System. Windows. Forms;

 

Namespace WindowsFormsApplication1

{

Public partial class Form1: Form

{

Public Form1 ()

{

InitializeComponent ();

}

 

Private void open form2 hide form1_Click (object sender, EventArgs e)

{

Form2 f = new Form2 ();

F. fatherForm = this;

F. Show ();

This. Hide ();

}

}

}

 

 

Form2

 

Using System;

Using System. Windows. Forms;

 

Namespace WindowsFormsApplication1

{

Public partial class Form2: Form

{

Public Form2 ()

{

InitializeComponent ();

}

 

Public Form1 fatherForm;

 

Private void open from3_Click (object sender, EventArgs e)

{

Form3 f = new Form3 ();

F. fatherForm = this;

F. Show ();

}

}

}

 

 

Form3

 

Using System;

Using System. Windows. Forms;

 

Namespace WindowsFormsApplication1

{

Public partial class Form3: Form

{

Public Form3 ()

{

InitializeComponent ();

}

 

Public Form2 fatherForm;

 

Private void disable form3from2 display from1_Click (object sender, EventArgs e)

{

FatherForm. fatherForm. Show ();

FatherForm. Close ();

This. Close ();

}

 

}

}

 


From tu jiankai's column

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.