라이브러리에서 상속 받고 업데이트해야하는 사용자 정의 컨트롤이 있습니다. 지금 당장 가지고있는 문제는 새 사용자 정의 컨트롤을 직접 인스턴스화 할 수 없다는 것입니다. 라이브러리에서 사용자 정의 컨트롤의 인스턴스를 만들고 전달하는 메서드를 호출해야합니다. 아래 샘플 코드를 확인하십시오.상속 된 사용자 정의 컨트롤 관련 문제
캐스팅을 사용해 보았는데 InvalidCastException이 발생했습니다. 나는 두 번째가 첫 번째 것보다 더 많은 저장 공간을 필요로하기 때문에 그렇게 생각한다.
도움을 주셔서 미리 감사드립니다. 당신이 ExtendedCustomControl를 인스턴스화되지 않습니다 때문입니다
Namespace ProjectA.Components
Public Class MainClass
Public Function CreateCustomControl() As CustomControl
Dim cc As CustomControl = Activator.CreateInstance(Of CustomControl)()
Return cc
End Function
End Class
Public Class CustomControl
Inherits System.Windows.Forms.UserControl
End Class
End Namespace
Namespace ProjectB
Public Class ExtendedCustomControl
Inherits ProjectA.Components.CustomControl
End Class
Public Class MainForm
Inherits System.Windows.Forms.Form
Private Sub CreateInstance()
Dim i As New ProjectA.Components.MainClass
Dim myControl As ExtendedCustomControl = i.CreateCustomControl
' InvalidCastException is thrown.
End Sub
End Class
End Namespace