• C#跨窗体操作(引用传递)


    现在给大家介绍一种最简单的跨窗体操作

    WinForm的窗体是一个类,C#的类是引用类型,那么我们应该可以将WinForm窗体类进行传递,那不就可以进行操作了么?

     

     

    效果描述:

    有三个窗体然后顺序分别是

    (1)点击第一个窗体中的按钮弹出第二个窗体,隐藏第一个窗体

    (2)第二个窗体到一定时间弹出第三个窗体

    (3)点击第三个窗体的按钮关闭第三个和第二个窗体,弹出第一个窗体

     

     

    From1

    [csharp] view plaincopy
    1. using System;  
    2. using System.Windows.Forms;  
    3.   
    4. namespace WindowsFormsApplication1  
    5. {  
    6.     public partial class Form1 : Form  
    7.     {  
    8.         public Form1()  
    9.         {  
    10.             InitializeComponent();  
    11.         }  
    12.   
    13.         private void 打开form2隐藏form1_Click(object sender, EventArgs e)  
    14.         {  
    15.             Form2 f = new Form2();  
    16.             f.fatherForm = this;  
    17.             f.Show();  
    18.             this.Hide();  
    19.         }  
    20.     }  
    21. }  


     

    Form2

    [csharp] view plaincopy
    1. using System;  
    2. using System.Windows.Forms;  
    3.   
    4. namespace WindowsFormsApplication1  
    5. {  
    6.     public partial class Form2 : Form  
    7.     {  
    8.         public Form2()  
    9.         {  
    10.             InitializeComponent();  
    11.         }  
    12.   
    13.         public Form1 fatherForm;  
    14.   
    15.         private void 打开from3_Click(object sender, EventArgs e)  
    16.         {  
    17.             Form3 f = new Form3();  
    18.             f.fatherForm = this;  
    19.             f.Show();  
    20.         }  
    21.     }  
    22. }  


     

    Form3

    [csharp] view plaincopy
    1. using System;  
    2. using System.Windows.Forms;  
    3.   
    4. namespace WindowsFormsApplication1  
    5. {  
    6.     public partial class Form3 : Form  
    7.     {  
    8.         public Form3()  
    9.         {  
    10.             InitializeComponent();  
    11.         }  
    12.   
    13.         public Form2 fatherForm;  
    14.   
    15.         private void 关闭form3from2显示from1_Click(object sender, EventArgs e)  
    16.         {  
    17.             fatherForm.fatherForm.Show();  
    18.             fatherForm.Close();  
    19.             this.Close();  
    20.         }  
    21.   
    22.     }  
    23. }  
  • 相关阅读:
    开发培训体会——写好代码的一些编码规则和设计原则
    开发培训体会——写好代码的一些基本原理
    传说中的奖励通报
    NetBeans 6.7 Milestone 2 Now Available for Download!
    Software Process Engine of BeyondTrack
    开发培训体会——代码的价值
    NetBeans 6.7 Milestone 2 Now Available for Download!
    传说中的奖励通报
    有关_sprintf函数重定义错误的思考
    Software Process Engine of BeyondTrack
  • 原文地址:https://www.cnblogs.com/shijiewutonghua/p/2980419.html
Copyright © 2020-2023  润新知