首页 > 学院 > 开发设计 > 正文

C#窗口间传值一例(子窗口向父窗口传值)

2019-11-17 04:18:34
字体:
来源:转载
供稿:网友

父窗口:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace mail
...{
    public partial class Form1: Form
    ...{
       
  
        PRivate string searchUrl = null;


        public Form1()
        ...{
            InitializeComponent();
        }

        public string SearchUrl
        ...{
            get
            ...{
                return searchUrl;
            }
            set
            ...{
                searchUrl = value;
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        ...{
            Form2 form2 = new Form2();
            form2.Owner = this;
            form2.ShowDialog();
        }
    }
}
 

子窗口:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace mail
...{
    public partial class Form2: Form
    ...{

        public Form2()
        ...{
            InitializeComponent();
        }

        private void setParent()
       ...{
             Form1 f = (Form1)this.Owner;
             f.SearchUrl = "www.baidu.com";
       }
    }
}


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表