码迷,mamicode.com
首页 > Windows程序 > 详细

C# 委托事件

时间:2020-03-20 12:39:22      阅读:96      评论:0      收藏:0      [点我收藏+]

标签:string   rgs   sub   tar   oid   int   window   one   eve   

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();
}
}

C# 委托事件

标签:string   rgs   sub   tar   oid   int   window   one   eve   

原文地址:https://www.cnblogs.com/jeenmablog/p/12530780.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!