Holding a form in memory

  • Thread starter Thread starter Alex Stevens
  • Start date Start date
A

Alex Stevens

Hi All,

I have a module level form variable as I want to react to custom events that
form raises:
Dim WithEvents m_frmSearchForm As frmPartSearch_Alt

When the user clicks the search button, I carry out this code:

If m_frmSearchForm Is Nothing Then
m_frmSearchForm = New frmPartSearch_Alt
With m_frmSearchForm
m_frmSearchForm.KeepOpen = False
m_frmSearchForm.MdiParent = MyBase.ParentForm
m_frmSearchForm.CaptionText = "Component Search"
m_frmSearchForm.SearchOption =
frmPartSearch_Alt.eSearchOptions.AllowSelect
m_frmSearchForm.Show()
End With
Else
m_frmSearchForm.Show()
End If

Which basically just loads the form and shows it.
The KeepOpen property allows the form to remain open.
The searchoption property tells to allow selection.
Both of these don't affect the problem.

Now, when the user closes the form using the x button, and then clicks the
search button again to execute this code then m_frmSearchForm isn't nothing
and the m_frmSearchForm.Show() is called, however nothing appears.

Can anybody help me with this????
When the x button is used to close a form, how can I ensure that the global
variable is emptied?
I don't want to open the form using showdialog.

Thanks

Alex Stevens
 
Now, when the user closes the form using the x button, and then clicks the
search button again to execute this code then m_frmSearchForm isn't nothing
and the m_frmSearchForm.Show() is called, however nothing appears.

If you need to keep the form around, don't call its close method, just call
its hide method.
When the x button is used to close a form, how can I ensure that the global
variable is emptied?

If you need to get rid of the form, close it and then call its dispose
method to free any resources it may be holding on to.

Perhaps this will help a little.
 
Back
Top