zoukankan      html  css  js  c++  java
  • 用事件进行窗口间参数传递

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                
            }
            private Form2 m_dlg;
    
            private void button1_Click(object sender, EventArgs e)
            {
                Form2 dlg = new Form2(richTextBox1.Text);
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    richTextBox1.Text = dlg.TextBoxValue;
                }
    
            }
    
            private void button2_Click(object sender, EventArgs e)
            {
                if (m_dlg == null)
                {
                    m_dlg = new Form2(richTextBox1.Text);
                    m_dlg.TextBoxChanged += new EventHandler<Form2.UpdataEventArgs>(m_dlg_textboxchanged);
                    m_dlg.FormClosed += new FormClosedEventHandler(
                        (sender2, e2) => { m_dlg = null; }
                    );
                    m_dlg.Show(this);
                }
                else
                {
                    m_dlg.Activate();
                }
    
            }
            private void m_dlg_textboxchanged(object sender1, Form2.UpdataEventArgs e1)
            {
                richTextBox1.Text = e1.texBox;
            }
    
        }
    }
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    namespace WindowsFormsApplication1
    {
        public partial class Form2 : Form
        {
            public Form2(string str)
            {
                InitializeComponent();
                TextBoxValue = str;
    
            }
            public event EventHandler<UpdataEventArgs> TextBoxChanged;
    
            private void Form2_Load(object sender, EventArgs e)
            {
    
            }
            public string TextBoxValue
            {
                get { return textBox1.Text; }
                set { textBox1.Text = value; }
            }
            private void textBox1_TextChanged(object sender, EventArgs e)
            {
    
            }
    
            private void textBox1_TextChanged_1(object sender, EventArgs e)
            {
                if (TextBoxChanged != null)
                {
                    UpdataEventArgs ex = new UpdataEventArgs();
                    ex.texBox = textBox1.Text;
                    TextBoxChanged(this, ex);
                }
            }
            public class UpdataEventArgs:EventArgs
            {
                public string texBox;
            }
    
    
        }
    }
        
    作者:wanglei_wan
        
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    香港2013迷你制汇节即将启幕
    neuroph轻量级神经网络框架
    java如何实现python的urllib.quote(str,safe='/')
    python 的日志logging模块
    Python 代码使用pdb调试技巧
    python中reload(module)的用法,以及错误提示
    Notepad++如何取消打开最近的历史文件
    机器学习--入门答疑
    计算机的启动过程
    缓存设计
  • 原文地址:https://www.cnblogs.com/because/p/2617527.html
Copyright © 2011-2022 走看看