zoukankan      html  css  js  c++  java
  • 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. }  
  • 相关阅读:
    css Tab选项卡1
    顺序栈的相关操作(初始化、入栈、出栈)
    用jdk在cmd下运行编译java程序
    UNIX标准及实现
    正则表达式
    gdb调试
    CSS 公共样式
    babel更新之后的 一些坑
    webpack4.x配置详情
    webpack4.x打包配置
  • 原文地址:https://www.cnblogs.com/shijiewutonghua/p/2980419.html
Copyright © 2011-2022 走看看