Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
MM .NET Tip 'O The Day - Getting a parent form reference
Message
Information générale
Forum:
ASP.NET
Catégorie:
The Mere Mortals .NET Framework
Titre:
MM .NET Tip 'O The Day - Getting a parent form reference
Divers
Thread ID:
00805425
Message ID:
00805425
Vues:
46
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
Répondre
Fil
Voir

Click here to load this message in the networking platform