Results 1 to 4 of 4

Thread: Close one form, Show the other! [resolved... blah]

  1. #1

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Close one form, Show the other! [resolved... blah]

    I know this has to be the world's easiest VB.NET question!

    Here's what I want: Show form1. Press the button on Form1, and form2 should show up. Form1 should then close.

    Here's what I did

    In a module:
    VB Code:
    1. Module Module1
    2.     Public f1 As New Form1
    3.     Public f2 As New Form2
    4.  
    5.     Sub Main()
    6.         f1.ShowDialog()
    7.     End Sub
    8.  
    9.  
    10. End Module

    In form1's button:

    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         f1.Close()
    3.         f2.Show()
    4.  
    5.  
    6.  
    7.     End Sub

    And that's it!

    Now when I click the button, form2 appears briefly and then disappears.

    Surely it has to be something simple. What am I missing?
    Last edited by mendhak; Jul 13th, 2004 at 04:04 AM.

  2. #2

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    f1 needs to be closed, so I cannot let it stay in memory.

  3. #3
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    VB Code:
    1. Module Module1
    2.     Public Sub Main()
    3.  
    4.         Dim MyForm As Form 'early-binding good :)
    5.  
    6.         MyForm = New Form1
    7.         MyForm.ShowDialog()
    8.  
    9.         'wait until form1 closes
    10.         MyForm = New Form2 'this kills the form1 instance
    11.         MyForm.ShowDialog()
    12.  
    13.     End Sub
    14. End Module
    15.  
    16. 'in form 1's button
    17. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    18.     Me.Close()
    19. End Sub

    I think its about time the "Late-Binding Demon" payed mendhak a visit, don't you kids? What a naughty froggy!.
    I don't live here any more.

  4. #4

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    I hug wossname!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width