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 之间传递  页面最终也是生成类对象。 

相关文章:

  • 2021-05-24
  • 2021-10-04
  • 2021-09-29
  • 2022-03-02
  • 2021-08-20
  • 2021-09-23
  • 2021-10-14
  • 2021-06-10
猜你喜欢
  • 2021-05-22
  • 2022-03-05
  • 2022-02-22
  • 2021-10-25
  • 2022-01-12
相关资源
相似解决方案