zoukankan      html  css  js  c++  java
  • 窗口之间即时控制

    打开子窗体Form2后,在往Form2上的控件上输入值的时候,Form1上的控件上的值也跟着变化。

    Form1代码:

    public Form1()
    {
    InitializeComponent();
    }

    private void button2_Click(object sender, EventArgs e)
    {
    Form2 f2 = new Form2();
    f2.TextBoxChanged += new EventHandler(
    (sender1, e1) =>
    { textBox2.Text = f2.TextBoxValue; }
    );
    f2.FormClosed += new FormClosedEventHandler(
    (sender2, e2) => { f2 = null; }
    );
    f2.Show(this);
    }

    Form2代码:

    public Form2():this(null)
    {

    }

    public string TextBoxValue
    {
    get { return textBox1.Text; }
    set { textBox1.Text = value; }
    }

    public event EventHandler TextBoxChanged;

    public Form2(string value) {
    InitializeComponent();
    TextBoxValue = value;
    }

    private void button1_Click(object sender, EventArgs e)
    {
    this.DialogResult = DialogResult.OK;
    }

    private void textBox1_TextChanged(object sender, EventArgs e)
    {
    if (TextBoxChanged != null)
    {
    TextBoxChanged(this, e);
    }
    }

  • 相关阅读:
    软链接和硬链接
    Hive的基本常识
    Hadoop
    Docker技术
    人生苦短,我用Python(6)
    人生苦短,我用Python(5)
    人生苦短,我用Python(4)
    openssl telnet openssh
    iptables
    http与httpd
  • 原文地址:https://www.cnblogs.com/niez1/p/7161301.html
Copyright © 2011-2022 走看看