在加载时隐藏主窗体

时间:2014-11-20 17:46:46

标签: .net vb.net

  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

这段代码怎么可能不起作用? 。即使注册表存在或不存在,它也不会隐藏Me表单

1 个答案:

答案 0 :(得分:0)

你不能这样做。

您有几个选择:

1。)你需要做Plutonix所说的。

2.。)在加载后处理事件中隐藏主表单:

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

3.)最后,使用一个事件处理程序(在它加载之后,它会运行事件):

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

您可以看到很多选项,但这是一个简单的解决方法。