C# Winfrom 页面传值

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

转载于:https://www.cnblogs.com/y112102/p/3723044.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值