Visual Basic > Visual Basic Forums > Visual Basic General > What can i have done with my form
Ask a questionAsk a question
 

AnswerWhat can i have done with my form

  • Saturday, November 07, 2009 10:19 AMAlvin Kuiper Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi
    No matter what i do, if i in form1 write me.hide
    or if i in form2 write form1.hide
    this don't work my form 1 is allways on show


    ALK

Answers

  • Saturday, November 07, 2009 3:51 PMJohnWein Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    You can't hide a Form before it's shown.  I assume the Form2.Show() code is in the Load event of Form1.  Use Form2.ShowDialog();

    • Marked As Answer byAlvin Kuiper Saturday, November 07, 2009 6:46 PM
    •  

All Replies

  • Saturday, November 07, 2009 11:01 AMFaraz Zone Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Try this

    form.visible = false

    this will work
  • Saturday, November 07, 2009 11:17 AMAlvin Kuiper Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    Hmm i use this:
    Dim ab As StreamReader = New StreamReader(Application.StartupPath & "/play.txt")
    
            valg = Trim(ab.ReadLine)
            If valg = "" Then
                Me.Visible = False
    
                Form2.Show()
    
            End If
    I can see my form 2 , but also Form1
    And in form 2 i try using:
    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Form1.Visible = False
    
    
        End Sub
    But still i can see my form1

    ALK
  • Saturday, November 07, 2009 1:21 PMDaveKlem Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    First, I think the slash in your path is the wrong one. Use "\"

    -dave
  • Saturday, November 07, 2009 3:51 PMJohnWein Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    You can't hide a Form before it's shown.  I assume the Form2.Show() code is in the Load event of Form1.  Use Form2.ShowDialog();

    • Marked As Answer byAlvin Kuiper Saturday, November 07, 2009 6:46 PM
    •  
  • Saturday, November 07, 2009 4:57 PMjwavila Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code

    if that's not working, can you post the entire Sub where the streamreader is?

    because this should work

    On Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            If TextBox1.Text = "" Then
                Form2.Show()
                Me.Hide()
            End If
        End Sub
    


    on Form2

    Private Sub Form2_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
            Form1.ShowDialog()
        End Sub
    



     

  • Saturday, November 07, 2009 5:06 PMDig-Boy Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    And one other unsolicited tip...

    You need to properly close your stream object after use.  I find the easiest way is to use the Using block, like this:
     
     
            Using ab As New StreamReader(Application.StartupPath & "\play.txt")
                valg = Trim(ab.ReadLine)
                If valg = "" Then
                    Me.Visible = False
                    Form2.Show()
                End If
            End Using
    
    I think John has hit the nail on the head...  in the Load event your form is not visible yet.  So You may want to move this code into the Form1.Shown event (which happens only after the first time the form becomes visible).  Also, consider placing a Me.Refresh call after Me.Visible = False to ensire that the changes are affected before Form2 is shown.
     
     
  • Saturday, November 07, 2009 6:46 PMAlvin Kuiper Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Thanks

    ALK