我有n个按钮的自定义控件,单击按钮将更改变量'state'并触发stateChanged事件,因此在主窗体中我只是将自定义控件和处理程序与myCustomControl1_stateChanged子放在一起。
Public Class myCustomControl
Private _mstate As Integer = 0
Public Event stateChanged()
Public Property State() As Integer
Get
State = _mstate
End Get
Set(value As Integer)
_ChangeState(value)
End Set
End Property
Public Sub New()
' This call is required by the designer.
InitializeComponent()
End Sub
Private Sub Buttton_Click(sender As Object, e As EventArgs) Handles btnAdd.Click,
btnEdit.Click, btnDel.Click, btnSave.Click, btnUndo.Click, btnPrint.Click
Dim newState As Integer = 0
If sender Is btnAdd Then newState = 1
If sender Is btnEdit Then newState = 2
If _mstate <> newState Then
_mstate = newState
RaiseEvent stateChanged()
End If
End Sub
结束班
但是此代码没有触发子myCustomControl1_stateChanged() 感谢