|
-
Mar 28th, 2004, 10:08 PM
#1
Thread Starter
Junior Member
Closing a form from other form
I am opening a form from other form, both need to be displayed at once, which I have been able to do. But what I need to be able is to close both forms when using a push button from only one of them.
I have tried the following code in the pushbutton:
Dim frmMain as new frmMain
frmMain.close
me.close
But this opens a new frmMain, I have also tried:
Dim frmMain a frmMain
frmMain.close
me.close
but this generates an error.
Thanks
-
Mar 29th, 2004, 01:52 AM
#2
Member
Ummm... Not sure exactly, but have you tried the
"application.exit" command? it works wonders...
it will close all forms under that current application.
Not sure if it will work for you, as im not sure exactly what your doing, but it sounds like your doing something very similiar to something i've done in the past. And i came here asking the exact same question, and ya,that was the fix i got 
hope it helps
---Flac
Everything great once started with the words "That will never catch on, you shouldnt even bother" be great, go against the crowed, do something stupid, you might become famous.
-
Mar 29th, 2004, 05:13 AM
#3
PowerPoster
Hi Flac,
Interesting signature!!
"do something stupid, you might become famous."
You mean like politicians???
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Mar 29th, 2004, 02:32 PM
#4
Thread Starter
Junior Member
Not what I was looking for
I do not want to close out the application.
I have a splash form, from the splash form I open another, lets call is Main for here. Then from the Main form when you press the Help button another form will open. What I then need is the Main form and help form to both be displayed, when you close the help form I need both the help and main form to close leaving only the splash form displayed.
Thanks
-
Mar 29th, 2004, 06:25 PM
#5
PowerPoster
Hi,
"frmMain.close
me.close"
That code SHOULD work. It works for me.
There must be something else at fault.
You do not make it clear where you have declared frmMain. Try declaring the instance of frmMain as Public in the Module.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Mar 29th, 2004, 06:54 PM
#6
Thread Starter
Junior Member
Still having an issue
Here are more details
App starts and loads the frmSplash
Within the frmSplash are Buttons to make a selection:
Here is the code within the Splash form:
Private Sub rbHTTP_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbHTTP.CheckedChanged
Dim frmHTTP As New frmHTTP
frmHTTP.Show()
End Sub
When you select the HTTP button the frmHTTP is displayed correctly.
On the frmHTTP is a button labeled "Help", when you press that button the frmHelp is displayed:
Here is the code:
Private Sub btHelp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btHelp.Click
Dim frmPasswordHelp = New frmPasswordHelp
frmPasswordHelp.show()
End Sub
At this point all three forms are displayed, and what I want to do is to press a button on the frmHelp that will close the frmHelp and the frmHTTP while leaving the frmSplash displayed:
Here are some examples of the code in the frmHelp that has not worked:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
frmHTTP.Close()
Me.Close()
End Sub
Also tried:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim frmHTTP As New frmHTTP
frmHTTP.Close()
Me.Close()
End Sub
All the above code does is to open a new frmHTTP and close it, leaving the orginal frmHTTP displayed.
I also tried:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim frmHTTP As frmHTTP
frmHTTP.Close()
Me.Close()
End Sub
Still no luck, just got the following error:
An unhandled exception of type 'System.NullReferenceException' occurred in WS2000 Simulator.exe
Why did they mess up a good thing, it was so easy in VB6!!
-
Mar 29th, 2004, 07:45 PM
#7
Addicted Member
VB Code:
Dim frmHTTP As New frmHTTP
frmHTTP.Close()
Me.Close()
End Sub
You are creating a new Instance of FrmHTTP hence "As New"
You need to create a Reference from the forms, using Public Properties is the easiest way
VB Code:
Public Class Form2
Inherits System.Windows.Forms.Form
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim frm As New Form3
frm.frm2 = Me
frm.Show()
End Sub
End Class
Public Class Form3
Inherits System.Windows.Forms.Form
Public frm2 As Form2
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
frm2.Close()
Me.Close()
End Sub
End Class
-Daryl
"Two More Rolls of Duct tape, and the world is mine!"
VB.NET Guru
-
Mar 30th, 2004, 06:16 AM
#8
PowerPoster
Hi,
ref my previous post.
If you are starting the application from frmSplash and not from a module, declare
Public frmHTTP As New frmHTTP
in the general section of frmSplash.
then
WILL work.
You are declaring it as private but expecting to reference it from frm Help.
Hi Dmyze,
"You are creating a new Instance of FrmHTTP hence "As New""
He has to create the instance. He has simply created it in the wrong place and with the wrong declaration. - unless I have completely misunderstood him.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Mar 30th, 2004, 02:52 PM
#9
Thread Starter
Junior Member
Solved, I cheated :)
I knew how to do it in VB6, so I wrote a quick app in VB6 and ran the upgrade Wizard to VB.Net to see the code:
Here is what I should have done...
Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command1.Click
Form3.DefInstance.Close()
Form2.DefInstance.Close()
End Sub
Thanks for all your help
-
Mar 30th, 2004, 04:46 PM
#10
PowerPoster
Hi,
"Form3.DefInstance.Close()
Form2.DefInstance.Close()"
I cannot follow the above.
If "Form3" is the base class and "DefInstance" is the name of the instance created, the above will not code.
or
"DefInstance" is not a property of a form.
I am using VB.NET 2003. Are you certain you are using VB.NET?
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Mar 30th, 2004, 10:02 PM
#11
Thread Starter
Junior Member
IT WORKS!!!!
Finally figured it out:
Just a recap or what I am trying to do.
I have three forms, from1, form2 and form3.
When the programs starts form1 is shown, with a pushbutton. When you press the push button on form1, form2 is displayed. Form2 also has a push button which when pressed will display form3. So all three forms are displayed at once. Then when you press a button on form3, form2 and form3 need to close while form1 stays open.
Here is the code....
For Form1:
Private Sub Button1_Click
Dim Form2 As New Form2
Form2.Show()
End Sub
For Form2:
Private Sub Button1_Click
Dim Form3 As New Form3
If Form3.ShowDialog = DialogResult.OK Then
Me.Close()
End If
End Sub
For Form3:
Private Sub Button1_Click
DialogResult = DialogResult.OK
me.close()
End Sub
Hope this helps others who may need to control several forms from one form. Thanks for everyones help and support.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|