2个窗体 Parent,Children
代码:
Parent
public partial class Parent : Form { public string parentValue = "parentValue"; Children sw; public Children cc; public Parent() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { //sw = new Children(); //sw.Owner = this; //sw.Show(); //sw = new Children(); //sw.childrenValue = "childrenValue"; //sw.Show(); sw = new Children(); sw.pp = this; sw.Show(); } }
Childrent
public partial class Children : Form { public string childrenValue { get; set; } public Parent pp; public Children() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { // Parent c = (Parent)this.Owner; // MessageBox.Show(c.parentValue); //MessageBox.Show(childrenValue); MessageBox.Show(pp.parentValue); } }
当然这里还有static 事件等等方式传值。
核心总结:
winfrom窗体传值 其实就是类 Parent和Children 之间传递 页面最终也是生成类对象。