Enabling/Disable/Hiding main Form

  • Thread starter Thread starter Ivan
  • Start date Start date
I

Ivan

I am used to VB6 and am not sure how to do this in
Vstudio .NET. I have a main form which calls other
forms. I want to disable that main form while other ones
are called. I tried hiding it and creating a new instance
of the main form when returning to it but than my
application is just creating more forms. How do I hide
the main form and return back to it when exiting another
form?
 
Code for Form1 Button:

Me.Hide()
Dim Form2 As New Form2()

Form2.Show()



Code for button on form2 to get back to form1

Dim form1 As New Form1()

form1.Show()

Me.Close()
 
* "Ivan said:
I am used to VB6 and am not sure how to do this in
Vstudio .NET. I have a main form which calls other
forms. I want to disable that main form while other ones
are called. I tried hiding it and creating a new instance
of the main form when returning to it but than my
application is just creating more forms. How do I hide
the main form and return back to it when exiting another
form?

<http://www.google.de/groups?selm=u#[email protected]>
 
Hi Ivan,

This isn't the OOP approach but...

Public Module SomeGlobals
'This reference is used by the other forms.
Public oMainForm As Form1
End Module

Class Form1
Sub New
oMainForm = Me
Sub btnShowFormX_Click
Me.Hide
Dim F As New FormX
F.Show

Class FormX
Sub btnReturnToMainForm_Click
Me.Close
oMainForm.Show

The reason the reference to the main form is stored in the SomeGlobals
Module is that you can't use Form1 to access the Form itself, as you could in
VB6.
Another method would be to pass the main form to FormX when you create
it - New FormX (Me). FormX would then store the reference internally. But that
would have to be done for every other form that may return to the main form.

Regards,
Fergus
 
If you're not ready to take the .NET form design architecture leap in its
entirety (I'm not), you can do something like the VB.NET form upgrade wizard
does. You can then access the form just like you used to for the most part
with show / hide: myforms.CustomerForm.Show for example.

Public Class myForms
Private Shared _CustomerForm As CustomerForm
Public Shared Property CustomerForm() As CustomerForm
Get
Return _CustomerForm
End Get
Set(ByVal Value As CustomerForm)
_CustomerForm = Value
End Set
End Property
End Class
End Class

Duncan Mackenzie (one of my favorite VB authors btw) has a good article
about getting a handler on what you are dealing with on MSDN:

http://msdn.microsoft.com/library/d...ltipleformsinvisualbasicnetupgradingtonet.asp
 
I am used to VB6 and am not sure how to do this in
Vstudio .NET. I have a main form which calls other
forms. I want to disable that main form while other ones
are called. I tried hiding it and creating a new instance
of the main form when returning to it but than my
application is just creating more forms. How do I hide
the main form and return back to it when exiting another
form?


I tend to think of forms as just another class just with ui objects

As with all classes you can add a handler to a class event.
Now when you inherit from Inherits System.Windows.Forms.Form
you class gets an Closing event. I would just create a function that
can handle the second class's Closing event

kinda like this

'In Main Form

Dim login As New Login()

AddHandler login.Closing, AddressOf Login_UnLoad
login.ShowDialog(Me)
Me.Visible = False


No further down in the main form class I would have this

Private Sub Login_UnLoad(ByVal sender As System.Object, ByVal e As
System.ComponentModel.CancelEventArgs)

'Perform Business Logic
Me.Visible = True

End Sub

now when the login form is unloaded it will raise an event of Closing
and my procedure that I added the handler to will catch that event and
procede wiht making my main form visible again
 
Back
Top