winform+c#之窗体之间的传值

winform+c#之窗体之间的传值

ID:14402494

大小:111.50 KB

页数:4页

时间:2018-07-28

winform+c#之窗体之间的传值_第1页
winform+c#之窗体之间的传值_第2页
winform+c#之窗体之间的传值_第3页
winform+c#之窗体之间的传值_第4页
资源描述:

《winform+c#之窗体之间的传值》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库

1、winform+c#之窗体之间的传值窗体传值可以分为两类。1、主窗体往子窗体传值有两种方法,一种是在子窗体提供重载构造函数,利用重载构造函数传递值,适用于传值数量比较少;第二种是,在子窗体中定义一个主窗体对象,然后就可以接收到主窗体的属性值了,适用于传值数量大。主窗体代码如下: public partial class frmParent : Form    {        private string strValueA = "";        public string StrValueA        {           

2、 get            {                return this.strValueA;            }            set { this.strValueA = value; }        }        public frmParent()        {            InitializeComponent();        }        private void button1_Click(object sender, EventArgs e)        {  

3、          this.strValueA = textBox1.Text;            frmChild frmchild = new frmChild();            frmchild.Owner = this;            frmchild.ShowDialog();            frmchild.Dispose();        }        private void button2_Click(object sender, EventArgs e)        {    

4、        frmChild frmchild = new frmChild(this.textBox1.Text);            string returnValue = "";            if (frmchild.ShowDialog() == DialogResult.OK)            {                returnValue = frmchild.Str;                this.textBox1.Text = returnValue;            

5、}        }    }子窗体代码如下:public partial class frmChild : Form    {        private string str;        public string Str        {            get { return this.str; }            set { this.str = value; }        }        private frmParent frmparent;        public frmChild()   

6、     {            InitializeComponent();        }        public frmChild(string str)        {            this.str = str;            InitializeComponent();            this.textBox1.Text = str;        }        private void frmChild_Load(object sender, EventArgs e)        {

7、            frmparent = (frmParent)this.Owner;            //this.textBox1.Text = frmparent.StrValueA;        }        private void button1_Click(object sender, EventArgs e)        {            //frmparent = (frmParent)this.Owner;            this.Str = this.textBox1.Text;

8、            this.DialogResult = DialogResult.OK;            this.Close();                    }    }2、从子

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。