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);
    }
    }

  • 相关阅读:
    Apache TomEE 入门指南
    Windows 7运行命令大全
    hibernate hql 大全
    maven常用命令
    php编译安装php-5.6
    nginx编译安装
    apache通过AD验证
    apache编译安装 httpd 2.2 httpd 2.4
    DC 辅域转主域
    tomcat安装配置
  • 原文地址:https://www.cnblogs.com/niez1/p/7161301.html
Copyright © 2011-2022 走看看