|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Why does this not work? What am I doing wrong?and greetings from the Netherlands. Trying to switch over from VB to VB.NET and struggling with something that seemed very simple: ============================ Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Form2.Show() Me.Close() End Sub End Class ============================= Looks rather simple: by clicking on button1, I want Form2 to show and Form1 to close. However, nothing happened, just a quick flash and the app exited. Someone told me to use ShowDialog instead of Show. This worked, but now Me.Close() does not work. How the **** do I close Form1?? Any help appreciated (this is driving me nuts!) Thanks Cees
Show quote
Hide quote
"Connectcase" <i***@connectcase.nl> wrote in What is happening is:news:1166991388.968820.181400@a3g2000cwd.googlegroups.com: > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles Button1.Click > Form2.Show() > Me.Close() > End Sub > > End Class > ============================= > Looks rather simple: by clicking on button1, I want Form2 to show and > Form1 to close. However, nothing happened, just a quick flash and the > app exited. Someone told me to use ShowDialog instead of Show. This > worked, but now Me.Close() does not work. How the **** do I close > Form1?? > 1. Click Handler Fires 2. Show displays form (the flicker) 3. Close executes in quick succession, shutting down the app (or form). What you want to do is use ShowDialog. ShowDialog stops execution until the dialog is returned. In your case this is ideal - in other situation, not so much (i.e. if you have background processes that need to continue even while a form is displayed). Try swapping show with showdialog and see how it works. Cees,
I am assuming that you are using VB 2005. Right-click the solution in Solution Explorer and choose Properties. Change the Shutdown Mode to "When last form closes". Kerry Moorman Show quoteHide quote "Connectcase" wrote: > Hi there, > > and greetings from the Netherlands. > > Trying to switch over from VB to VB.NET and struggling with something > that seemed very simple: > ============================ > Public Class Form1 > Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles MyBase.Load > End Sub > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles Button1.Click > Form2.Show() > Me.Close() > End Sub > > End Class > ============================= > Looks rather simple: by clicking on button1, I want Form2 to show and > Form1 to close. However, nothing happened, just a quick flash and the > app exited. Someone told me to use ShowDialog instead of Show. This > worked, but now Me.Close() does not work. How the **** do I close > Form1?? > > Any help appreciated (this is driving me nuts!) > > Thanks > > Cees > > I found this under the "Application" Tab for the Project properties,
not the Solution properties. That's what you're talking about, right? Thanks, Robin S. ----------------------------- Show quoteHide quote "Kerry Moorman" <KerryMoor***@discussions.microsoft.com> wrote in message news:19F4ED58-CF5D-4D86-9E00-D151E09498D9@microsoft.com... > Cees, > > I am assuming that you are using VB 2005. > > Right-click the solution in Solution Explorer and choose Properties. > > Change the Shutdown Mode to "When last form closes". > > Kerry Moorman > > > > "Connectcase" wrote: > >> Hi there, >> >> and greetings from the Netherlands. >> >> Trying to switch over from VB to VB.NET and struggling with something >> that seemed very simple: >> ============================ >> Public Class Form1 >> Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As >> System.EventArgs) Handles MyBase.Load >> End Sub >> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e >> As >> System.EventArgs) Handles Button1.Click >> Form2.Show() >> Me.Close() >> End Sub >> >> End Class >> ============================= >> Looks rather simple: by clicking on button1, I want Form2 to show and >> Form1 to close. However, nothing happened, just a quick flash and the >> app exited. Someone told me to use ShowDialog instead of Show. This >> worked, but now Me.Close() does not work. How the **** do I close >> Form1?? >> >> Any help appreciated (this is driving me nuts!) >> >> Thanks >> >> Cees >> >> Robin,
Yes, its under the Application tab. I got there by right-clicking WindowsApplication1 in the Solution Explorer window and choosing Properties. Kerry Moorman Show quoteHide quote "RobinS" wrote: > I found this under the "Application" Tab for the Project properties, > not the Solution properties. That's what you're talking about, right? > > Thanks, > Robin S. > ----------------------------- > "Kerry Moorman" <KerryMoor***@discussions.microsoft.com> wrote in > message news:19F4ED58-CF5D-4D86-9E00-D151E09498D9@microsoft.com... > > Cees, > > > > I am assuming that you are using VB 2005. > > > > Right-click the solution in Solution Explorer and choose Properties. > > > > Change the Shutdown Mode to "When last form closes". > > > > Kerry Moorman > > > > > > > > "Connectcase" wrote: > > > >> Hi there, > >> > >> and greetings from the Netherlands. > >> > >> Trying to switch over from VB to VB.NET and struggling with something > >> that seemed very simple: > >> ============================ > >> Public Class Form1 > >> Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As > >> System.EventArgs) Handles MyBase.Load > >> End Sub > >> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e > >> As > >> System.EventArgs) Handles Button1.Click > >> Form2.Show() > >> Me.Close() > >> End Sub > >> > >> End Class > >> ============================= > >> Looks rather simple: by clicking on button1, I want Form2 to show and > >> Form1 to close. However, nothing happened, just a quick flash and the > >> app exited. Someone told me to use ShowDialog instead of Show. This > >> worked, but now Me.Close() does not work. How the **** do I close > >> Form1?? > >> > >> Any help appreciated (this is driving me nuts!) > >> > >> Thanks > >> > >> Cees > >> > >> > > > Got it. I have my options set to display the Solution always, even if I
only have one project. So my solution doesn't have the same properties as you get when you choose the WindowsApplication1 -- that's the actual project. Anyway, that was a handy thing to know. Thanks! Robin S. -------------------------------- Show quoteHide quote "Kerry Moorman" <KerryMoor***@discussions.microsoft.com> wrote in message news:D8199C8F-1B64-419A-B602-60266CF0D6B3@microsoft.com... > Robin, > > Yes, its under the Application tab. > > I got there by right-clicking WindowsApplication1 in the Solution > Explorer > window and choosing Properties. > > Kerry Moorman > > > "RobinS" wrote: > >> I found this under the "Application" Tab for the Project properties, >> not the Solution properties. That's what you're talking about, right? >> >> Thanks, >> Robin S. >> ----------------------------- >> "Kerry Moorman" <KerryMoor***@discussions.microsoft.com> wrote in >> message news:19F4ED58-CF5D-4D86-9E00-D151E09498D9@microsoft.com... >> > Cees, >> > >> > I am assuming that you are using VB 2005. >> > >> > Right-click the solution in Solution Explorer and choose >> > Properties. >> > >> > Change the Shutdown Mode to "When last form closes". >> > >> > Kerry Moorman >> > >> > >> > >> > "Connectcase" wrote: >> > >> >> Hi there, >> >> >> >> and greetings from the Netherlands. >> >> >> >> Trying to switch over from VB to VB.NET and struggling with >> >> something >> >> that seemed very simple: >> >> ============================ >> >> Public Class Form1 >> >> Private Sub Form1_Load(ByVal sender As System.Object, ByVal e >> >> As >> >> System.EventArgs) Handles MyBase.Load >> >> End Sub >> >> Private Sub Button1_Click(ByVal sender As System.Object, ByVal >> >> e >> >> As >> >> System.EventArgs) Handles Button1.Click >> >> Form2.Show() >> >> Me.Close() >> >> End Sub >> >> >> >> End Class >> >> ============================= >> >> Looks rather simple: by clicking on button1, I want Form2 to show >> >> and >> >> Form1 to close. However, nothing happened, just a quick flash and >> >> the >> >> app exited. Someone told me to use ShowDialog instead of Show. >> >> This >> >> worked, but now Me.Close() does not work. How the **** do I close >> >> Form1?? >> >> >> >> Any help appreciated (this is driving me nuts!) >> >> >> >> Thanks >> >> >> >> Cees >> >> >> >> >> >> >> Thanks guys for all the responses, but none of it worked.
I already tried ShowDialog instead of Show, but this does not close Form1. It leaves it open. Changing the Shutdown Mode I also tried, but no luck; Form1 is still open. I am beginning to wonder if it is easier for new developpers to learn VB.NET than it is for those who already know VB6 and keep comparing VB.NET to that. All I wanted was a simple replacement for the "Unload Me" statement in VB6 and I thought "Me.Close" would be that replacement, but no luck. I can understand that Microsoft has some funny rule about a child form still depending on a parent form and therefore not being able to close the parent etc. etc., but what about a nice error message or warning? When I started to dig into VB.NET , I had no idea that the following 4 lines (as simple as they are) would keep me busy for so long: ------------------------------------------ Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Form2.ShowDialog() Me.Close() End Sub ------------------------------------------ Maybe it's time to dust off the old Delphi 7 cd roms..... Thanks Cees RobinS wrote: Show quoteHide quote > Got it. I have my options set to display the Solution always, even if I > only have one > project. So my solution doesn't have the same properties as you get when > you > choose the WindowsApplication1 -- that's the actual project. > > Anyway, that was a handy thing to know. Thanks! > Robin S. > -------------------------------- > "Kerry Moorman" <KerryMoor***@discussions.microsoft.com> wrote in > message news:D8199C8F-1B64-419A-B602-60266CF0D6B3@microsoft.com... > > Robin, > > > > Yes, its under the Application tab. > > > > I got there by right-clicking WindowsApplication1 in the Solution > > Explorer > > window and choosing Properties. > > > > Kerry Moorman > > > > > > "RobinS" wrote: > > > >> I found this under the "Application" Tab for the Project properties, > >> not the Solution properties. That's what you're talking about, right? > >> > >> Thanks, > >> Robin S. > >> ----------------------------- > >> "Kerry Moorman" <KerryMoor***@discussions.microsoft.com> wrote in > >> message news:19F4ED58-CF5D-4D86-9E00-D151E09498D9@microsoft.com... > >> > Cees, > >> > > >> > I am assuming that you are using VB 2005. > >> > > >> > Right-click the solution in Solution Explorer and choose > >> > Properties. > >> > > >> > Change the Shutdown Mode to "When last form closes". > >> > > >> > Kerry Moorman > >> > > >> > > >> > > >> > "Connectcase" wrote: > >> > > >> >> Hi there, > >> >> > >> >> and greetings from the Netherlands. > >> >> > >> >> Trying to switch over from VB to VB.NET and struggling with > >> >> something > >> >> that seemed very simple: > >> >> ============================ > >> >> Public Class Form1 > >> >> Private Sub Form1_Load(ByVal sender As System.Object, ByVal e > >> >> As > >> >> System.EventArgs) Handles MyBase.Load > >> >> End Sub > >> >> Private Sub Button1_Click(ByVal sender As System.Object, ByVal > >> >> e > >> >> As > >> >> System.EventArgs) Handles Button1.Click > >> >> Form2.Show() > >> >> Me.Close() > >> >> End Sub > >> >> > >> >> End Class > >> >> ============================= > >> >> Looks rather simple: by clicking on button1, I want Form2 to show > >> >> and > >> >> Form1 to close. However, nothing happened, just a quick flash and > >> >> the > >> >> app exited. Someone told me to use ShowDialog instead of Show. > >> >> This > >> >> worked, but now Me.Close() does not work. How the **** do I close > >> >> Form1?? > >> >> > >> >> Any help appreciated (this is driving me nuts!) > >> >> > >> >> Thanks > >> >> > >> >> Cees > >> >> > >> >> > >> > >> > >> Hey, I think I did it (must be the Christmas spirit or something)....
I put the ShutDown mode on "When last form closes", changed "ShowDialog" back to "Show" and it worked!!! So the button on Form1 clicks to: Form2.Show() Me.Close() Closing Form2 with the X-button in the corner also removes the app from memory (checked the Task Manager), that was another thing I was worried about. Thanks guys for the input.... Cheers, Cees Connectcase wrote: Show quoteHide quote > Thanks guys for all the responses, but none of it worked. > > I already tried ShowDialog instead of Show, but this does not close > Form1. It leaves it open. > Changing the Shutdown Mode I also tried, but no luck; Form1 is still > open. > > I am beginning to wonder if it is easier for new developpers to learn > VB.NET than it is for those who already know VB6 and keep comparing > VB.NET to that. > > All I wanted was a simple replacement for the "Unload Me" statement in > VB6 and I thought "Me.Close" would be that replacement, but no luck. > > I can understand that Microsoft has some funny rule about a child form > still depending on a parent form and therefore not being able to close > the parent etc. etc., but what about a nice error message or warning? > > When I started to dig into VB.NET , I had no idea that the following 4 > lines (as simple as they are) would keep me busy for so long: > > ------------------------------------------ > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles Button1.Click > Form2.ShowDialog() > Me.Close() > End Sub > ------------------------------------------ > > Maybe it's time to dust off the old Delphi 7 cd roms..... > > Thanks > > Cees > > RobinS wrote: > > Got it. I have my options set to display the Solution always, even if I > > only have one > > project. So my solution doesn't have the same properties as you get when > > you > > choose the WindowsApplication1 -- that's the actual project. > > > > Anyway, that was a handy thing to know. Thanks! > > Robin S. > > -------------------------------- > > "Kerry Moorman" <KerryMoor***@discussions.microsoft.com> wrote in > > message news:D8199C8F-1B64-419A-B602-60266CF0D6B3@microsoft.com... > > > Robin, > > > > > > Yes, its under the Application tab. > > > > > > I got there by right-clicking WindowsApplication1 in the Solution > > > Explorer > > > window and choosing Properties. > > > > > > Kerry Moorman > > > > > > > > > "RobinS" wrote: > > > > > >> I found this under the "Application" Tab for the Project properties, > > >> not the Solution properties. That's what you're talking about, right? > > >> > > >> Thanks, > > >> Robin S. > > >> ----------------------------- > > >> "Kerry Moorman" <KerryMoor***@discussions.microsoft.com> wrote in > > >> message news:19F4ED58-CF5D-4D86-9E00-D151E09498D9@microsoft.com... > > >> > Cees, > > >> > > > >> > I am assuming that you are using VB 2005. > > >> > > > >> > Right-click the solution in Solution Explorer and choose > > >> > Properties. > > >> > > > >> > Change the Shutdown Mode to "When last form closes". > > >> > > > >> > Kerry Moorman > > >> > > > >> > > > >> > > > >> > "Connectcase" wrote: > > >> > > > >> >> Hi there, > > >> >> > > >> >> and greetings from the Netherlands. > > >> >> > > >> >> Trying to switch over from VB to VB.NET and struggling with > > >> >> something > > >> >> that seemed very simple: > > >> >> ============================ > > >> >> Public Class Form1 > > >> >> Private Sub Form1_Load(ByVal sender As System.Object, ByVal e > > >> >> As > > >> >> System.EventArgs) Handles MyBase.Load > > >> >> End Sub > > >> >> Private Sub Button1_Click(ByVal sender As System.Object, ByVal > > >> >> e > > >> >> As > > >> >> System.EventArgs) Handles Button1.Click > > >> >> Form2.Show() > > >> >> Me.Close() > > >> >> End Sub > > >> >> > > >> >> End Class > > >> >> ============================= > > >> >> Looks rather simple: by clicking on button1, I want Form2 to show > > >> >> and > > >> >> Form1 to close. However, nothing happened, just a quick flash and > > >> >> the > > >> >> app exited. Someone told me to use ShowDialog instead of Show. > > >> >> This > > >> >> worked, but now Me.Close() does not work. How the **** do I close > > >> >> Form1?? > > >> >> > > >> >> Any help appreciated (this is driving me nuts!) > > >> >> > > >> >> Thanks > > >> >> > > >> >> Cees > > >> >> > > >> >> > > >> > > >> > > >> Cees,
It depend very much from where you did start your program. In VB.Net it can be in I thought about 12 different ways. If you use the mainform method for startup. Than that class "me" is direct the last one if you do me.close otherwise you have to use a method that belongs to the way you start program. Anyway. This beneath closes the program forever in a decent way. Environment.exit(0) 'where 0 is for normal mode as you can see in your console box. And to be from the Benelux is real no uniquem in these newsgroups. Cor Show quoteHide quote "Connectcase" <i***@connectcase.nl> schreef in bericht news:1167052432.353676.130670@48g2000cwx.googlegroups.com... > Hey, I think I did it (must be the Christmas spirit or something).... > > I put the ShutDown mode on "When last form closes", changed > "ShowDialog" back to "Show" and it worked!!! > > So the button on Form1 clicks to: > > Form2.Show() > Me.Close() > > Closing Form2 with the X-button in the corner also removes the app from > memory (checked the Task Manager), that was another thing I was worried > about. > > Thanks guys for the input.... > > Cheers, > > Cees > > > Connectcase wrote: >> Thanks guys for all the responses, but none of it worked. >> >> I already tried ShowDialog instead of Show, but this does not close >> Form1. It leaves it open. >> Changing the Shutdown Mode I also tried, but no luck; Form1 is still >> open. >> >> I am beginning to wonder if it is easier for new developpers to learn >> VB.NET than it is for those who already know VB6 and keep comparing >> VB.NET to that. >> >> All I wanted was a simple replacement for the "Unload Me" statement in >> VB6 and I thought "Me.Close" would be that replacement, but no luck. >> >> I can understand that Microsoft has some funny rule about a child form >> still depending on a parent form and therefore not being able to close >> the parent etc. etc., but what about a nice error message or warning? >> >> When I started to dig into VB.NET , I had no idea that the following 4 >> lines (as simple as they are) would keep me busy for so long: >> >> ------------------------------------------ >> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As >> System.EventArgs) Handles Button1.Click >> Form2.ShowDialog() >> Me.Close() >> End Sub >> ------------------------------------------ >> >> Maybe it's time to dust off the old Delphi 7 cd roms..... >> >> Thanks >> >> Cees >> >> RobinS wrote: >> > Got it. I have my options set to display the Solution always, even if I >> > only have one >> > project. So my solution doesn't have the same properties as you get >> > when >> > you >> > choose the WindowsApplication1 -- that's the actual project. >> > >> > Anyway, that was a handy thing to know. Thanks! >> > Robin S. >> > -------------------------------- >> > "Kerry Moorman" <KerryMoor***@discussions.microsoft.com> wrote in >> > message news:D8199C8F-1B64-419A-B602-60266CF0D6B3@microsoft.com... >> > > Robin, >> > > >> > > Yes, its under the Application tab. >> > > >> > > I got there by right-clicking WindowsApplication1 in the Solution >> > > Explorer >> > > window and choosing Properties. >> > > >> > > Kerry Moorman >> > > >> > > >> > > "RobinS" wrote: >> > > >> > >> I found this under the "Application" Tab for the Project properties, >> > >> not the Solution properties. That's what you're talking about, >> > >> right? >> > >> >> > >> Thanks, >> > >> Robin S. >> > >> ----------------------------- >> > >> "Kerry Moorman" <KerryMoor***@discussions.microsoft.com> wrote in >> > >> message news:19F4ED58-CF5D-4D86-9E00-D151E09498D9@microsoft.com... >> > >> > Cees, >> > >> > >> > >> > I am assuming that you are using VB 2005. >> > >> > >> > >> > Right-click the solution in Solution Explorer and choose >> > >> > Properties. >> > >> > >> > >> > Change the Shutdown Mode to "When last form closes". >> > >> > >> > >> > Kerry Moorman >> > >> > >> > >> > >> > >> > >> > >> > "Connectcase" wrote: >> > >> > >> > >> >> Hi there, >> > >> >> >> > >> >> and greetings from the Netherlands. >> > >> >> >> > >> >> Trying to switch over from VB to VB.NET and struggling with >> > >> >> something >> > >> >> that seemed very simple: >> > >> >> ============================ >> > >> >> Public Class Form1 >> > >> >> Private Sub Form1_Load(ByVal sender As System.Object, ByVal e >> > >> >> As >> > >> >> System.EventArgs) Handles MyBase.Load >> > >> >> End Sub >> > >> >> Private Sub Button1_Click(ByVal sender As System.Object, >> > >> >> ByVal >> > >> >> e >> > >> >> As >> > >> >> System.EventArgs) Handles Button1.Click >> > >> >> Form2.Show() >> > >> >> Me.Close() >> > >> >> End Sub >> > >> >> >> > >> >> End Class >> > >> >> ============================= >> > >> >> Looks rather simple: by clicking on button1, I want Form2 to show >> > >> >> and >> > >> >> Form1 to close. However, nothing happened, just a quick flash and >> > >> >> the >> > >> >> app exited. Someone told me to use ShowDialog instead of Show. >> > >> >> This >> > >> >> worked, but now Me.Close() does not work. How the **** do I close >> > >> >> Form1?? >> > >> >> >> > >> >> Any help appreciated (this is driving me nuts!) >> > >> >> >> > >> >> Thanks >> > >> >> >> > >> >> Cees >> > >> >> >> > >> >> >> > >> >> > >> >> > >> >
PrintDocument_PrintPage goes into endless loop until e.HasMorePages=False
Print font not available after assigning PrinterName Goodbye microsoft.public.dotnet.languages.vb Rename registry Key [folder/ branch] regex expressions MySQL and MyOleDB How to get the checked columns in DataGridView Deleting controls Autorun on USB Flash Drive Webbrowser |
|||||||||||||||||||||||