SLイベントの使用
1654 ワード
プログラムでよく使うので、書いてバックアップしました.
eg:
参照:
eg:
public partial class BarChart
{
private const string Str = " ";
public BarChart()
{
InitializeComponent();
}
/// <summary>
/// </summary>
private void OKButton_Click(object sender, RoutedEventArgs e)
{
var tp = new TransferParmEventArgs(Str);
TransferParmEvent(tp);
DialogResult = true;
}
/// <summary>
/// </summary>
protected virtual void TransferParmEvent(TransferParmEventArgs e)
{
if (TransferParm != null)
TransferParm(this, e);
}
public event TransferParmEventHandler TransferParm;
public delegate void TransferParmEventHandler(object sender, TransferParmEventArgs e);
public sealed class TransferParmEventArgs : EventArgs
{
private readonly List<string> _value;
public TransferParmEventArgs(List<string> value)
{
_value = value;
}
public List<string> Value
{
get { return _value; }
}
}
}
参照:
BarChart bar = new BarChart();
bar.TransferParm += new BarChart.TransferParmEventHandler(barChart_TransferParm);
void barChart_TransferParm(object sender, BarChart.TransferParmEventArgs e)
{
var str = e.Value;
}