I have a control which is mounted within a form. I need to implement a callback, so that the control can make the parent form do something. My plan was to create a MustInherit class with MustOverride methods, and make the form inherit the MustInherit class. However, Visual Basic tells me that the form cannot inherit more than one class, which means that it can either inherit my MustInherit class, or System.Windows.Forms.Form, but not both.
I’d like to be able to do something like the following in my control:
private Parent as iRiksProjectParent
public sub AttachParent(ByRef parent as iRiksProjectParent)
Parent = parent
End Sub
…
private sub ProcessData()
dim theProcessedData as String
...
parent.DoSomethingWithTheData(theProcessedData)
End Sub
How can I do this?
To directly answer your question: You can make your
MustInheritclass inherit fromSystem.Windows.Forms.Form. Then, if your Form inherits from your custom class, it automatically also inherits fromSystem.Windows.Forms.Form.To solve your problem: Don’t use an explicit callback. Simply have your custom control raise an event:
That way, the Form can simply handle the event: