Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Guest mutant
Posted
If you use as windows.forms.form you will not ba able to access functions or variables that are inside the form class.
Posted
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.

Posted

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

Fat kids are harder to kidnap

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...