1

我有带有 n 个按钮的自定义控件,单击按钮将更改变量“状态”并触发 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

结束类

但是这段代码没有触发 sub myCustomControl1_stateChanged() 谢谢

4

0 回答 0