关闭Form1如果FileExists + Open Form2

时间:2017-04-22 15:11:59

标签: vb.net forms

如果文件存在,我尝试关闭或隐藏Form cnx并打开Form Product。 但有些事情是错的,我不明白为什么这不起作用。

    Private Sub cnx_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    strFileName = "app.txt"
    strBasePath = Application.StartupPath
    If My.Computer.FileSystem.FileExists(strFileName) = True Then
        Product.Show()
        Me.Hide()
    ElseIf My.Computer.FileSystem.FileExists(strFileName) = False Then
        MessageBox.Show("File App.config is Missing! Create a new Database.",
            "Something is Wrong!", MessageBoxButtons.OK, MessageBoxIcon.Warning)
    End If
End Sub

感谢。

1 个答案:

答案 0 :(得分:0)

你可以这样做,虽然可能不是最佳的。

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    hideForm(Me)
    Form2.Show()
End Sub

Private Sub hideForm(form As Form)
    form.Opacity = 0.0F
    form.ShowInTaskbar = False
End Sub

还记得在Form2下添加,否则你的程序将在关闭Form2后保持打开状态。

Private Sub Form2_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
    Form1.Close()
End Sub