2
개체 인스턴스의 복제를 만들려고합니다.다른 인스턴스에 이벤트 처리기 할당 복사
새 인스턴스를 만들고 속성 값을 복사해도 아무런 문제가 없지만 원래 개체 인스턴스에는 해당 이벤트에 할당 된 이벤트 처리기가 있습니다. 새 인스턴스에 이벤트 처리기를 복사하려면 어떻게해야합니까?
감사합니다 ..
다음 코드 샘플은 ...
Public Sub ButtonClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
MessageBox.Show(sender.Name + "was clicked")
End Sub
Public Sub CloneButton()
Dim newButton = New Button
newButton.Name = Button1.Name + "_Clone"
newButton.Text = Button1.Text
newButton.Width = Button1.Width
newButton.Height = Button1.Height
'Some code here to copy Button1's event handler ButtonClick,
'so when the new button is clicked "Button1_Clone was clicked" is displayed.
End Sub
언어? 플랫폼? 샘플 코드를 알려주세요. –
의견을 댓글로 쓰지 말고 수정하십시오. –
[원본 개체의 이벤트를 완전 복제 된 복제본에 첨부하는 방법] 가능한 복제본 (http://stackoverflow.com/questions/4038465/how-to-attach-the-events-of-an-original-object -to-a-deep-copied-clone) – Breeze