-1
  Private Sub FrmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If My.Computer.Registry.GetValue("HKEY_CURRENT_USER\1227", "1227", Nothing) Is Nothing Then
            Me.Show()
        Else
            Form2.Show()
            Me.Hide()
        End If
End Sub

How is possible that this code is not working ? . It won't hide the Me form even if the Registry exist or not

1337user
  • 7
  • 1
  • 10
  • Does the order of Form2.Show() and Me.Hide() matter? Try putting Me.Hide() first. – Sean Cox Nov 20 '14 at 17:52
  • It won't hide Main form on form load, don't know what to do. – 1337user Nov 20 '14 at 17:55
  • Form Load runs the first time the form is shown; if you want to avoid showing the form at all, start the app from Sub Main and show the one you want. [see this link](http://stackoverflow.com/a/25554057/1070452) for how to – Ňɏssa Pøngjǣrdenlarp Nov 20 '14 at 17:56
  • So this is like third form which decide which form to show first ? – 1337user Nov 20 '14 at 18:02
  • did I say a third form, or did I say `Sub Main`? did you even look at the link (which has step by step instructions)? – Ňɏssa Pøngjǣrdenlarp Nov 20 '14 at 18:04
  • Yes i looked the link. And i don't see any step by step instructions on this link. I understand this answer [link](http://stackoverflow.com/questions/21866280/vb-net-load-form-and-hide-it) More than yours. When i use Sub Main () i must disable application framework that makes my application looks different and ugly – 1337user Nov 20 '14 at 18:10
  • 1
    Your Load event handler runs *because* the Show() method was called, you cannot un-show it. Use the [Startup event](http://msdn.microsoft.com/en-us/library/t4zch4d2%28v=vs.90%29.aspx) instead, assign the Me.MainForm property. – Hans Passant Nov 20 '14 at 19:47
  • "ugly" is very simply fixed with `Application.EnableVisualStyles()` – Ňɏssa Pøngjǣrdenlarp Nov 21 '14 at 18:57

1 Answers1

0

You can't do it that way.

You have a couple options:

1.) You need to either do what Plutonix said.

2.) Handle the hiding of the main form in an event AFTER loading:

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    Form2.Show()
    Hide()
End Sub

3.) Finally, use an event handler (after it's loaded, itll run events):

Private Sub FrmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Timer1.Start()
End Sub

Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
    'Perform your if logic here...
    Form2.Show()
    Timer1.Stop()
End Sub

Private Sub Form2_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    Form1.Hide()
End Sub

There are obviously several options as you can see, but that's an easy workaround.

Keith
  • 1,331
  • 2
  • 13
  • 18