zoukankan      html  css  js  c++  java
  • winfrom窗体 子窗体和父窗体实时传值。

    using System;
    using System.Collections.Generic;
    using System.Text;
    
    namespace WF.ThreadFrom
    {
    
        public delegate void TextChangedEventHander(object sender,TextChangedEventEventArgs e);
    
        public class TextChangedEventEventArgs:EventArgs
        {
            private string msg;
    
            public string Msg
            {
                get { return msg; }
            }
    
            public TextChangedEventEventArgs(string message)
            {
                this.msg = message;
            }
        }
    }
    
    
    using System;
    using System.Collections.Generic;
    using System.Text;
    
    namespace WF.ThreadFrom
    {
        public delegate void SelectionChangedEventHandler(object sender, SelectionChangedEventArgs e);
    
        public class SelectionChangedEventArgs:EventArgs 
        {
            private string m_selection;
    
            //本属性用于传递事件数据
            public string Selection
            {
                get { return m_selection; }
            }
    
            public SelectionChangedEventArgs(string selection)
            {
                m_selection = selection;
            }
        }
    }
    
    
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    
    namespace WF.ThreadFrom
    {
        public partial class Form2 : Form
        {
            public event SelectionChangedEventHandler SelectionChanged;
    
            public event TextChangedEventHander TextChanged;
    
            public Form2()
            {
                InitializeComponent();
            }
    
            private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
            {
                if (SelectionChanged != null)
                {
                    SelectionChangedEventArgs E = new SelectionChangedEventArgs(comboBox1.Text);
                    SelectionChanged(this, E);
                }
    
              
            }
    
            private void textBox1_TextChanged(object sender, EventArgs e)
            {
                if (TextChanged != null)
                {
                    TextChangedEventEventArgs E = new TextChangedEventEventArgs(textBox1.Text);
                    TextChanged(this, E);
                }
            }
        }
    }
    
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    
    namespace WF.ThreadFrom
    {
        public partial class Form1 : Form
        {
            private Form2 frm;
    
            public Form1()
            {
                InitializeComponent();
    
                frm = new Form2();
                frm.SelectionChanged += new SelectionChangedEventHandler(frm_SelectionChanged);
                frm.TextChanged += new TextChangedEventHander(frm_TextChanged);
            }
    
            void frm_TextChanged(object sender, TextChangedEventEventArgs e)
            {
                textBox1.Text = e.Msg;
            }
    
            void frm_SelectionChanged(object sender, SelectionChangedEventArgs e)
            {
                textBox1.Text = e.Selection;
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                frm.ShowDialog();
            }
    
            private void textBox1_TextChanged(object sender, EventArgs e)
            {
    
            }
    
      
    
        }
    }
    
  • 相关阅读:
    转:桩模块 stub 和驱动模块 driver
    音频中PCM的概念
    pthread_exit
    为什么匿名内部类参数必须为final类型
    原创:同步与异步、阻塞与非阻塞
    (转)C语言中长度为0的数组
    编码问题
    查看Android程序使用内存
    C++中class与struct的区别(struct的类型名同时可以作为变量名)
    asn1c
  • 原文地址:https://www.cnblogs.com/Mr0909/p/2283321.html
Copyright © 2011-2022 走看看