This tip is taken straight out of the MM .NET Dev Guide topic "Getting a Reference to a Control's Parent Form".
All .NET Windows Forms controls have a FindForm method that allows you to get a reference to the form on which a control resides. Unfortunately, this method does not work when a control is instantiating (usually the very time you need a reference to the parent form!).
To address this issue, you can call the static GetParentForm method of the MM .NET Form Manager to get a reference to the parent form.
For example, in C#:
public class MyTextBox : TextBox
{
public MyTextBox()
{
Form ParentForm = mmAppDesktop.FormMgr.GetParentForm(this);
}
}
And in VB .NET:
Public Class MyTextBox
Inherits TextBox
Public Sub New()
Dim ParentForm As Form = mmAppDesktop.FormMgr.GetParentForm(Me)
End Sub
End Class
Additional Note: The Form Manager works its "magic" by keeping track of the last instantiated form as well as getting a reference to the currently active form.
Regards,
Kevin McNeish
Eight-Time .NET MVP
VFP and iOS Author, Speaker & Trainer
Oak Leaf Enterprises, Inc.
Chief Architect, MM Framework
http://www.oakleafsd.com