By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,573 Members | 1,777 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,573 IT Pros & Developers. It's quick & easy.

Enabling/Disable/Hiding main Form

P: n/a
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?
Nov 20 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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" <Iv*****@aol.com> wrote in message
news:0f****************************@phx.gbl...
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?

Nov 20 '05 #2

P: n/a
* "Ivan" <Iv*****@aol.com> scripsit:
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%23xQOutWDHA.2100%40TK2MSFTNGP11.phx. gbl>

--
Herfried K. Wagner
MVP VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #3

P: n/a
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
Nov 20 '05 #4

P: n/a
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/de...adingtonet.asp

--
Justin Weinberg

Designing a PrintDocument? Drawing to forms?
Check out GDI+ Architect at www.mrgsoft.com
"Ivan" <Iv*****@aol.com> wrote in message
news:0f****************************@phx.gbl...
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?

Nov 20 '05 #5

P: n/a
On Tue, 14 Oct 2003 08:09:06 -0700, "Ivan" <Iv*****@aol.com> wrote:
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
Nov 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.