• C#Winform窗体中传值


    在窗体Form2中定义公有属性Form2Value,获取和设置textBox1的文本值 
    并且还定义一个accept事件
    
    
    public string Form2Value 
    { 
         get 
         { 
              return this.textBox1.Text; 
         } 
         set 
        { 
             this.textBox1.Text = value; 
        } 
    } 
    
    public event EventHandler accept; 
    
    private void button1_Click ( object sender , EventArgs e ) 
    { 
         if ( accept != null ) 
         { 
              accept ( this , EventArgs.Empty ); //当窗体触发事件,传递自身引用 
         } 
    } 
    
    
    在窗体Form1中
    
    
    Form2 f2 = new Form2 ( ); 
    f2.accept += new EventHandler ( f2_accept ); 
    f2.Show ( ); 
    
    void f2_accept ( object sender , EventArgs e )
    { 
         //事件的接收者通过一个简单的类型转换得到Form2的引用 
         Form2 f2 = (Form2) sender; 
         //接收到Form2的textBox1.Text 
         this.textBox1.Text = f2.Form2Value; 
    }
    

      

  • 相关阅读:
    TSQL语句
    约束
    数据库创建
    递归
    函数
    结构体
    集合
    jquery中的select
    正则表达式
    多表单提交
  • 原文地址:https://www.cnblogs.com/XuPengLB/p/6085157.html
Copyright © 2020-2023  润新知