- /// <summary>
- /// 1.声明一个委托,用于代理一系列"无返回"及"不带参"的自定义方法
- /// </summary>
- public delegate void 委托名EventHandler(object sender, EventArgs e);
- public partial class 用户控件类名: UserControl
- {
- /// <summary>
- /// 2.在值改变时发生
- /// </summary>
- public event 委托名EventHandler 事件名;
- private int _selectedPosition = 0;
- /// <summary>
- /// 控件的某属性
- /// </summary>
- public int SelectedPosition
- {
- get { return _selectedPosition; }
- set { _selectedPosition = value; }
- }
- private void 控件的某操作_Clicked(object sender, EventArgs e)
- {
- //todo:...
- //3.值已经改变
- if (事件名 != null)
- 事件名(this,EventArgs.Empty);
- }
- }
- //--------------------
- //4.在客户端调用
- this.ucToothPosition1.OnValueChanged += new ValueChangedEventHandler(ucToothPosition1_OnValueChanged);
- void ucToothPosition1_OnValueChanged(object sender, EventArgs e)
- {
- this.DialogResult = DialogResult.OK;
- }