110,545
社区成员
发帖
与我相关
我的任务
分享
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
MyTexBox myTextBox = new MyTexBox();
this.Controls.Add(myTextBox);
myTextBox.MyTextChanged += new MyTexBox.MyTextChangedHandler(MyTextChanged);
myTextBox.MyText = "sfsf";
}
private void MyTextChanged(string strText)
{
MessageBox.Show(strText);
}
}
public class MyTexBox : TextBox
{
public delegate void MyTextChangedHandler(string strText);
public event MyTextChangedHandler MyTextChanged;
private string _MyText;
public string MyText
{
get { return _MyText; }
set
{
_MyText = value;
if (MyTextChanged != null)
{
MyTextChanged(_MyText);
}
}
}
}
}