(首先抱歉,因为我不知道如何正确命名这个问题。)
当我从 GUI 中的按钮调用它时,我需要执行某种操作:
Listview1.Items.Add(LVItem)
问题是我需要从其他类做,我的意思是不继承 ListView 来引发自己的ItemIsAdded
事件等......
那么这可能吗?
我将举一个例子来更好地理解我:
我有Form1
课:
Public Class Form1
Public WithEvents _undoManager As UndoManager
Private Sub Form1_Load(sender As Object, e As EventArgs) _
Handles MyBase.Load
_undoManager = New UndoManager(Listview1)
End Sub
Private Sub Button_AddItem_Click(sender As Object, e As EventArgs) _
Handles Button_AddItem.Click
Listview1.Items.Add(LVItem)
End Sub
End Class
和UndoManager
班级:
Public Class UndoManager
Delegate Sub AddDelegate(item As ListViewItem)
Private Shared LV As ListView
Private Shared ListView_Add_Method = New AddDelegate(AddressOf LV.Items.Add)
Public Sub New(ByVal ListView As ListView)
LV = ListView
End Sub
' Here code to capture when the delegate method is called...
private sub blahblahblah() handles ListView_Add_Method.IsCalled
' blah blah blah
end sub
End Class
然后当我在类中调用以执行某种操作然后添加项目时,UndoManager
类需要捕获(如果操作在调用方法之前运行或在调用方法之后运行,则真的没有问题)。Listview1.Items.Add(LVItem)
Form1
Items.Add()