C# 文档编辑器中查找替换的实现(自定义事件)
第一步:定义一个自定义的参数类型,主要目的是把数据传递给事件。
查找参数类型
public class SearchEventArgsClass:EventArgs
{
private string searchString;
public SearchEventArgsClass(string str)
{
this.searchString = str;
}
public string SearchString
{
get { return this.searchString; }
set { this.searchString = value; }
}
}
替换参数类型
public delegate void ReplaceEventHandle(object sender, ReplaceEventArgClass e);
public class ReplaceEventArgClass : EventArgs
{
private string searchString;
private string replaceString;
public ReplaceEventArgClass(string str1,string str2)
{
this.searchString = str1;
this.replaceString = str2;
}
public string SearchString
{
get { return this.searchString; }
set { this.searchString = value; }
}
public string ReplaceString
{
get { return this.replaceString; }
set { this.replaceString = value; }
}
}