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
        
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    windows下 安装 rabbitMQ 及操作常用命令
    C#中关于DataGridView行和列的背景色-前景色设置
    使用Linq判断DataTable数据是否重复
    C#用mouse_event模拟鼠标点击的问题
    ApartmentState.STA
    使用WebBrowser,内存一直增加的解决办法
    HOT SUMMER 每天都是不一样,积极的去感受生活 C#关闭IE相应的窗口 .
    您访问的URL地址不被允许。
    CMSIS-DAP for STLink V2.1 and STLink v2.1 mini adapter
    DG449 High Voltage Single SPDT Analog Switch in SOT23-8
  • 原文地址:https://www.cnblogs.com/because/p/2617527.html
Copyright © 2011-2022 走看看