473,417 Members | 1,429 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,417 software developers and data experts.

Me.Close() Question

Hi,

In my program, the user can navigate to many different
forms. When they go to the next form, I want the form they
have left to close.

However, the forms aren't closing. Can anyone tell me what
I'm doing wrong? Here is a sample snippet of code where
the user can return to the main form while simultaneously
closing the previous form.

Thank you!

Private Sub btnBack_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
btnBack.Click

' Goes Back to the main form
Dim objMain As New frmMain()

objMain.ShowDialog()

' Closes the Travel Screen
Me.Close()
End Sub
Nov 20 '05 #1
7 2499
The problem is that you are calling Close() *after* calling ShowDialog() on
the other form.

ShowDialog() will pause execution at that point until the form being shown
has closed.

Try using the Show() method instead of ShowDialog(), or alternatively (but
messy), call close before calling ShowDialog.
Hope this helps,

Trev.

"Alice" <an*******@discussions.microsoft.com> wrote in message
news:eb****************************@phx.gbl...
Hi,

In my program, the user can navigate to many different
forms. When they go to the next form, I want the form they
have left to close.

However, the forms aren't closing. Can anyone tell me what
I'm doing wrong? Here is a sample snippet of code where
the user can return to the main form while simultaneously
closing the previous form.

Thank you!

Private Sub btnBack_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
btnBack.Click

' Goes Back to the main form
Dim objMain As New frmMain()

objMain.ShowDialog()

' Closes the Travel Screen
Me.Close()
End Sub

Nov 20 '05 #2
Thanks for your response.

Unfortunately, neither method seems to be working. I have
used both, but now the program breaks.

If you do want to open another form and close the previous
one, how should it be coded? (For example, a simple splash
screen that should close as the user clicks to enter the
program?)

Many thanks,
Alice
-----Original Message-----
The problem is that you are calling Close() *after* calling ShowDialog() onthe other form.

ShowDialog() will pause execution at that point until the form being shownhas closed.

Try using the Show() method instead of ShowDialog(), or alternatively (butmessy), call close before calling ShowDialog.
Hope this helps,

Trev.

"Alice" <an*******@discussions.microsoft.com> wrote in messagenews:eb****************************@phx.gbl...
Hi,

In my program, the user can navigate to many different
forms. When they go to the next form, I want the form they have left to close.

However, the forms aren't closing. Can anyone tell me what I'm doing wrong? Here is a sample snippet of code where
the user can return to the main form while simultaneously closing the previous form.

Thank you!

Private Sub btnBack_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
btnBack.Click

' Goes Back to the main form
Dim objMain As New frmMain()

objMain.ShowDialog()

' Closes the Travel Screen
Me.Close()
End Sub

.

Nov 20 '05 #3
Hi Alice,

I have a password form that closes when the correct pwd is entered; works
very simply but it does not directly open the next form, as it opens an mdi
container that ultimately is the base form of the mdi app.

However, opening one form from another is pretty easy. I tested the
following with 2 forms - formfirst and formsecond. This is the code from
the first form,which opens the second and closes itself.
Dim newmdichild As New formsecond

Me.Close()

newmdichild.Show()

Now the code for the second form is the same, except it calls formfirst.

This works fine with show(), but with showdialog(), it exhibits strange
behavior - each remains open and simply displays a second, third etc
instance of itself.

Can you show me your code, and the error message you get when the program
breaks?

HTH,

Bernie

"Alice" <an*******@discussions.microsoft.com> wrote in message
news:01****************************@phx.gbl...
Thanks for your response.

Unfortunately, neither method seems to be working. I have
used both, but now the program breaks.

If you do want to open another form and close the previous
one, how should it be coded? (For example, a simple splash
screen that should close as the user clicks to enter the
program?)

Many thanks,
Alice
-----Original Message-----
The problem is that you are calling Close() *after*

calling ShowDialog() on
the other form.

ShowDialog() will pause execution at that point until the

form being shown
has closed.

Try using the Show() method instead of ShowDialog(), or

alternatively (but
messy), call close before calling ShowDialog.
Hope this helps,

Trev.

"Alice" <an*******@discussions.microsoft.com> wrote in

message
news:eb****************************@phx.gbl...
Hi,

In my program, the user can navigate to many different
forms. When they go to the next form, I want the form they have left to close.

However, the forms aren't closing. Can anyone tell me what I'm doing wrong? Here is a sample snippet of code where
the user can return to the main form while simultaneously closing the previous form.

Thank you!

Private Sub btnBack_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
btnBack.Click

' Goes Back to the main form
Dim objMain As New frmMain()

objMain.ShowDialog()

' Closes the Travel Screen
Me.Close()
End Sub

.

Nov 20 '05 #4
* "Alice" <an*******@discussions.microsoft.com> scripsit:
In my program, the user can navigate to many different
forms. When they go to the next form, I want the form they
have left to close.

However, the forms aren't closing. Can anyone tell me what
I'm doing wrong? Here is a sample snippet of code where
the user can return to the main form while simultaneously
closing the previous form.

Thank you!

Private Sub btnBack_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
btnBack.Click

' Goes Back to the main form
Dim objMain As New frmMain()

objMain.ShowDialog()

' Closes the Travel Screen
Me.Close()
End Sub


Using 'ShowDialog' will block the execution until the form you showed is
closed. Then the 'Me.Close()' will be executed.

"Solution":

<http://groups.google.com/groups?selm=u%23xQOutWDHA.2100%40TK2MSFTNGP11.phx. gbl>

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #5
Hi Bernie,

My original code (using ShowDialog) just left every form
still open, but the program didn't break. So I changed it
to .Show(), and it suddenly exits the program. Here is the
message it gives after it crashes:

The program '[3088] TravelCenter.exe' has exited with code
0 (0x0).

Here is the code I'm using:

Private Sub btnEnter_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
btnEnter.Click

' Open the Main Form
Dim objMain As New frmMain()

objMain.Show()

' Closes Welcome Screen
Me.Close()
End Sub

Thank you for your help!
-----Original Message-----
Hi Alice,

I have a password form that closes when the correct pwd is entered; worksvery simply but it does not directly open the next form, as it opens an mdicontainer that ultimately is the base form of the mdi app.

However, opening one form from another is pretty easy. I tested thefollowing with 2 forms - formfirst and formsecond. This is the code fromthe first form,which opens the second and closes itself.
Dim newmdichild As New formsecond

Me.Close()

newmdichild.Show()

Now the code for the second form is the same, except it calls formfirst.
This works fine with show(), but with showdialog(), it exhibits strangebehavior - each remains open and simply displays a second, third etcinstance of itself.

Can you show me your code, and the error message you get when the programbreaks?

HTH,

Bernie

"Alice" <an*******@discussions.microsoft.com> wrote in messagenews:01****************************@phx.gbl...
Thanks for your response.

Unfortunately, neither method seems to be working. I have used both, but now the program breaks.

If you do want to open another form and close the previous one, how should it be coded? (For example, a simple splash screen that should close as the user clicks to enter the
program?)

Many thanks,
Alice
>-----Original Message-----
>The problem is that you are calling Close() *after*

calling ShowDialog() on
>the other form.
>
>ShowDialog() will pause execution at that point until the
form being shown
>has closed.
>
>Try using the Show() method instead of ShowDialog(), or

alternatively (but
>messy), call close before calling ShowDialog.
>
>
>Hope this helps,
>
>Trev.
>
>
>
>"Alice" <an*******@discussions.microsoft.com> wrote in

message
>news:eb****************************@phx.gbl...
>> Hi,
>>
>> In my program, the user can navigate to many

different >> forms. When they go to the next form, I want the form

they
>> have left to close.
>>
>> However, the forms aren't closing. Can anyone tell me

what
>> I'm doing wrong? Here is a sample snippet of code where >> the user can return to the main form while

simultaneously
>> closing the previous form.
>>
>> Thank you!
>>
>> Private Sub btnBack_Click(ByVal sender As
>> System.Object, ByVal e As System.EventArgs) Handles
>> btnBack.Click
>>
>> ' Goes Back to the main form
>> Dim objMain As New frmMain()
>>
>> objMain.ShowDialog()
>>
>> ' Closes the Travel Screen
>> Me.Close()
>> End Sub
>
>
>.
>

.

Nov 20 '05 #6
Hi Alice,

You're closing the main form of the app, I suspect. This form is the base
form, so the programs exits.

What you have to do is make the main form an mdi container (in its
properties). Then develop a simple menu for that form; have one of the menu
options open a child form, which then has a button that can open a different
child form and close itself, etc. This way, the mdi container (the parent
form) remains open all the time and serves as a lauching point for any menu
option you place in it.

If you need some help setting this up, try first to do it and let me know
where you run into a problem. The menu calls should look something like
this:
Private Sub MenuItem31_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MenuItem31.Click

Dim newmdichild As New formfirst

newmdichild.MdiParent = Me

newmdichild.Show()

End Sub

Then, inside formfirst, a button click event like this to launch a different
form and close itself:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim newmdichild As New formsecond

Me.Close()

newmdichild.Show()

End Sub

HTH,

Bernie

"Alice" <an*******@discussions.microsoft.com> wrote in message
news:05****************************@phx.gbl...
Hi Bernie,

My original code (using ShowDialog) just left every form
still open, but the program didn't break. So I changed it
to .Show(), and it suddenly exits the program. Here is the
message it gives after it crashes:

The program '[3088] TravelCenter.exe' has exited with code
0 (0x0).

Here is the code I'm using:

Private Sub btnEnter_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
btnEnter.Click

' Open the Main Form
Dim objMain As New frmMain()

objMain.Show()

' Closes Welcome Screen
Me.Close()
End Sub

Thank you for your help!
-----Original Message-----
Hi Alice,

I have a password form that closes when the correct pwd

is entered; works
very simply but it does not directly open the next form,

as it opens an mdi
container that ultimately is the base form of the mdi app.

However, opening one form from another is pretty easy. I

tested the
following with 2 forms - formfirst and formsecond. This

is the code from
the first form,which opens the second and closes itself.
Dim newmdichild As New formsecond

Me.Close()

newmdichild.Show()

Now the code for the second form is the same, except it

calls formfirst.

This works fine with show(), but with showdialog(), it

exhibits strange
behavior - each remains open and simply displays a

second, third etc
instance of itself.

Can you show me your code, and the error message you get

when the program
breaks?

HTH,

Bernie

"Alice" <an*******@discussions.microsoft.com> wrote in

message
news:01****************************@phx.gbl...
Thanks for your response.

Unfortunately, neither method seems to be working. I have used both, but now the program breaks.

If you do want to open another form and close the previous one, how should it be coded? (For example, a simple splash screen that should close as the user clicks to enter the
program?)

Many thanks,
Alice

>-----Original Message-----
>The problem is that you are calling Close() *after*
calling ShowDialog() on
>the other form.
>
>ShowDialog() will pause execution at that point until the form being shown
>has closed.
>
>Try using the Show() method instead of ShowDialog(), or
alternatively (but
>messy), call close before calling ShowDialog.
>
>
>Hope this helps,
>
>Trev.
>
>
>
>"Alice" <an*******@discussions.microsoft.com> wrote in
message
>news:eb****************************@phx.gbl...
>> Hi,
>>
>> In my program, the user can navigate to many different >> forms. When they go to the next form, I want the form
they
>> have left to close.
>>
>> However, the forms aren't closing. Can anyone tell me
what
>> I'm doing wrong? Here is a sample snippet of code where >> the user can return to the main form while
simultaneously
>> closing the previous form.
>>
>> Thank you!
>>
>> Private Sub btnBack_Click(ByVal sender As
>> System.Object, ByVal e As System.EventArgs) Handles
>> btnBack.Click
>>
>> ' Goes Back to the main form
>> Dim objMain As New frmMain()
>>
>> objMain.ShowDialog()
>>
>> ' Closes the Travel Screen
>> Me.Close()
>> End Sub
>
>
>.
>

.

Nov 20 '05 #7
Cor
Hi Alice,

I think from what you describe the dialog form is that what you need
although there are also other ways to do it.

I made a sample for you with something extra in it to hide the control box
in the splash screen if you use that and to go back from form2 automticly
when button1 is clicked on that. It closes than automaticly.

I hope it helps?

Cor

\\\Main form
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim frm As New Form2
Me.Hide()
frm.ShowDialog()
Me.Show()
frm.dispose
End Sub
///
\\\Sub form 2
Private Sub Form2_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Me.CancelButton = Me.Button1
Me.ControlBox = False
End Sub
///

In my program, the user can navigate to many different
forms. When they go to the next form, I want the form they
have left to close.

However, the forms aren't closing. Can anyone tell me what
I'm doing wrong? Here is a sample snippet of code where
the user can return to the main form while simultaneously
closing the previous form.

Thank you!

Private Sub btnBack_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
btnBack.Click

' Goes Back to the main form
Dim objMain As New frmMain()

objMain.ShowDialog()

' Closes the Travel Screen
Me.Close()
End Sub

Nov 20 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: InvisibleMan | last post by:
Hi, I feel a little dumb for asking this (considering im writing TSQL) but there doesn't seem to be any definitive answers on the search engines... Okay I understand that if you open the ADO...
3
by: Martin | last post by:
Hi, this is probably a very basic question but I'm not a javascript expert! Sure you get this asked often! Did some research but can't get it working. I'm thankful for any help! Thanks! ...
4
by: Raymond Wilk | last post by:
I used javascript to open a new window, then used the following to close the new window on the next click: <body onBlur="self.close()" onClick="self.close()" bgcolor="#FFFFFF"> On the new window...
3
by: Woody Splawn | last post by:
I have some code which I will show below that opens a SQLDataReader, gets some information and then closes. My question is, what is the proper way to close? Do I close the reader first and then...
8
by: Paul W | last post by:
Hi - in an asp.net application, how should I close out a sqlclient.connection? What combination and order of Conn.close conn.dispose conn=nothing Should I use? Specifically, is the...
2
by: mark | last post by:
I put this question on a new thread because, in spirit, it is a new question. I apologize that I have difficulty formulating the proper question. My application performs matrix computations on...
7
by: MichaelK | last post by:
What's the best way to close current window silently after finished a process. I'm using the the javascritpt window.close() or top.window.close(), but it fires a confirmation window. Just want to...
7
by: tapanreddy | last post by:
I am looking to perform an action when we close the window using the close tab at the top of the screen. I know how to do it using a close button but I was wondering if there is way to achieve the...
15
by: Mahernoz | last post by:
Hi Friends, I simply want to print a report by opening a popup, calling the print function and closing the window after the user has printed the report. I have 2 functions.... in c# The...
5
by: =?Utf-8?B?Q2hyaXM=?= | last post by:
I am showing a form by ShowModal(). I put a button on that form. When a user clicks the button a MsgBox will show with question "do you want to close?" yes/no. How to handle the situation: - user...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.