首页 > Windows开发 > 详细

WinForm--(子窗体改变父窗体中控件的属性-委托)

时间:2014-04-09 19:54:24      阅读:630      评论:0      收藏:0      [点我收藏+]

子窗体(FromA)改变父窗体(MainForm)中控件的属性(利用委托)

bubuko.com,布布扣

bubuko.com,布布扣

代码(MainForm.cs):

bubuko.com,布布扣
namespace TestSelect
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            FormA fm = new FormA();
            fm.change+=new FormA.ChangeMainForm(ChangeLable);
            fm.ShowDialog();
        }

        private void ChangeLable(string str)
        {
            label1.Text = str;
        }
    }
}
bubuko.com,布布扣

代码(FormA.cs):

bubuko.com,布布扣
namespace TestSelect
{
    public partial class FormA : Form
    {
        public FormA()
        {
            InitializeComponent();
        }
        public delegate void ChangeMainForm(string str);
        public event ChangeMainForm change;
        private void button1_Click(object sender, EventArgs e)
        {
            change(textBox1.Text);
        }
    }
}
bubuko.com,布布扣

其实简单的改变父窗体不需要用到这个东西,不过个人感觉还是挺好的!(例:窗体关系A-B-C,需要C change A)

 

WinForm--(子窗体改变父窗体中控件的属性-委托),布布扣,bubuko.com

WinForm--(子窗体改变父窗体中控件的属性-委托)

原文:http://www.cnblogs.com/guo-pc31/p/3653739.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!