Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
MM .NET Tip 'O The Day - Getting a parent form reference
Message
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Title:
MM .NET Tip 'O The Day - Getting a parent form reference
Miscellaneous
Thread ID:
00805425
Message ID:
00805425
Views:
45
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);
		// Perform processing
	}
}
And in VB .NET:
Public Class MyTextBox
   Inherits TextBox
   
   Public Sub New()
      Dim ParentForm As Form = mmAppDesktop.FormMgr.GetParentForm(Me)
      ' Perform processing
   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
Reply
Map
View

Click here to load this message in the networking platform