最近自己继续对WinForm进行学习,把自己学习中的一点体会写出来。

WinForm中的窗体传值有多种方法,自己结合相关资料总结了一下,大概有5种方式(或者更多):

1、通过 ShowDialog()进行传值;

2、通过改造构造函数进行传值(加参数);

3、通过公共静态类进行传值;

4、通过绑定事件进行传值;

5、使用Attribute(本人属初学,尚需深入研究,希望高手给与指正)

代码如下:

主窗体代码:

 

WinForm中页面传值的方式using System;
WinForm中页面传值的方式
using System.Collections.Generic;
WinForm中页面传值的方式
using System.ComponentModel;
WinForm中页面传值的方式
using System.Data;
WinForm中页面传值的方式
using System.Drawing;
WinForm中页面传值的方式
using System.Text;
WinForm中页面传值的方式
using System.Windows.Forms;
WinForm中页面传值的方式
WinForm中页面传值的方式
namespace WinTestValue
}

F001_ShowDialog的代码:

WinForm中页面传值的方式public partial class F001_ShowDialog : Form
    }

 

F002_GouZao的代码:

WinForm中页面传值的方式    public partial class F002_GouZao : Form
    }

 

F004_ComonClass的代码:

WinForm中页面传值的方式    public partial class F004_ComonClass : Form
    }

 

F003_Event的代码:

WinForm中页面传值的方式    public partial class F003_Event : Form
    }

 

自定义的委托和事件的代码:

WinForm中页面传值的方式    public delegate void MyEventHandler(object sender, MyEvent e);
WinForm中页面传值的方式    
public class MyEvent : EventArgs
    }

 

WinForm中页面传值的方式    // 定义一个公共数据类
WinForm中页面传值的方式
    public static class ComonData
    }

 

Attribute部分还没完成,有些方面没有搞明白,过段时间再加上。

相关文章: