zoukankan      html  css  js  c++  java
  • C# 委托事件

    public partial class SubWindow : Window
    {
    public delegate void PassValuesHandler(object sender, PassValuesEventArgs e);

    public event PassValuesHandler PassValuesEvent;

    public SubWindow()
    {
    InitializeComponent();
    }

    private void btnOK_Click(object sender, RoutedEventArgs e)
    {
    string value1 = tbValue1.Text; // Text Property return value is string type .
    int value2;
    Int32.TryParse(tbValue2.Text, out value2);

    PassValuesEventArgs args = new PassValuesEventArgs(value1, value2);
    if ( PassValuesEvent!=null)
    {
    PassValuesEvent(this, args);
    }

    this.Close();
    }
    }


    public partial class MainWindow : Window
    {
    public MainWindow()
    {
    InitializeComponent();
    }

    private void btnOpenSubWindow_Click(object sender, RoutedEventArgs e)
    {
    SubWindow subWindow = new SubWindow();

    // 订阅事件
    subWindow.PassValuesEvent += new SubWindow.PassValuesHandler(ReceiveValues);

    subWindow.Show();
    }

    private void ReceiveValues(object sender, PassValuesEventArgs e)
    {
    this.tbValue1.Text = e.Value1;
    this.tbValue2.Text = e.Value2.ToString();
    }
    }

  • 相关阅读:
    HDU 1813 Escape from Tetris
    BZOJ 2276 Temperature
    BZOJ 4499 线性函数
    BZOJ 3131 淘金
    HDU 5738 Eureka
    POJ 2409 Let it Bead
    POJ 1286 Necklace of Beads
    POJ 1696 Space Ant
    Fox And Jumping
    Recover the String
  • 原文地址:https://www.cnblogs.com/jeenmablog/p/12530780.html
Copyright © 2011-2022 走看看