Eloff Posted April 16, 2003 Posted April 16, 2003 The Form1.ActiveForm thing works fairly well, but if you minimize the form while it is trying to do something with it, Form1.ActiveForm isn't set and an exception occurs. A better way may be: Put this in the module: Public MyForm As System.Windows.Forms.Form Public Sub init(ByRef thisForm As System.Windows.Forms.Form) MyForm = thisForm End Sub And call init() from the windows form designer generated code: Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call init(Me) End Sub Put that in all your forms and MyForm will always reference the last constructed form (the active form!). I'm pretty new to this so I'm not sure if this is a good or a bad idea, but it seems to work great for me! Dan Quote
Guest mutant Posted April 16, 2003 Posted April 16, 2003 If you use as windows.forms.form you will not ba able to access functions or variables that are inside the form class. Quote
Moderators Robby Posted April 16, 2003 Moderators Posted April 16, 2003 Eloff, is this in response to something? Quote Visit...Bassic Software
Eloff Posted April 22, 2003 Author Posted April 22, 2003 Eloff, is this in response to something? Just something I wanted to share. If you use as windows.forms.form you will not ba able to access functions or variables that are inside the form class. I've never tried to do that so it doesn't bother me, I just needed a way to access the controls on the form, add new ones or manipulate existing ones. Quote
iebidan Posted April 22, 2003 Posted April 22, 2003 Declaring a public variable that contains the object and reference to the form will only consume resources and memory, and what will happen when you get more than one form on your project opened at the same time??? you'll need to declare multiple variables each one???. I'll rather declare it when I need it and dispose it when the form is no longer needed, if you use this you'll never free the memory used. Regards Quote Fat kids are harder to kidnap
Cassio Posted April 22, 2003 Posted April 22, 2003 Eloff can you talk more about this Form1.ActiveForm error? I´ve always used it and never notice it could throw an exception. Quote Stream of Consciousness (My blog)
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.