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

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

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

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

代码(MainForm.cs):

WinForm--(子窗体改变父窗体中控件的属性-委托)
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;
        }
    }
}
WinForm--(子窗体改变父窗体中控件的属性-委托)

代码(FormA.cs):

WinForm--(子窗体改变父窗体中控件的属性-委托)
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);
        }
    }
}
WinForm--(子窗体改变父窗体中控件的属性-委托)

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

 

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

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

上一篇:PS合成制作夜幕下的恐怖城堡


下一篇:精美网站标志