事件委托例子(可跨窗口操作)


事件委托例子:

using System;
using System.Drawing;
using System.Windows.Forms;

namespace 跨窗體調用控件
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form2 f = new Form2();
f.ChangeColor += new ChangeFormColor(f_ChangeColor);
f.Show();
}
void f_ChangeColor(bool topmost)
{
this.BackColor = Color.LightBlue;
this.Text = "改變成功";
}
}
}

  

using System;  
using System.Windows.Forms;

namespace 跨窗體調用控件
{
public delegate void ChangeFormColor(bool topmost);
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
public event ChangeFormColor ChangeColor;
private void button1_Click(object sender, EventArgs e)
{
ChangeColor(true);//執行委托實例
}
}
}

  

參考:http://blog.csdn.net/bdstjk/article/details/7004035

下載例子


注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
粤ICP备14056181号  © 2014-2020 ITdaan.com