2017-04-22 104 views
0

如果存在文件,并尝试关闭或隐藏表单cnx并打开Form Product。 但有些事情是错误的,我不明白为什么这不工作。关闭Form1如果FileExists +打开Form2

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 

谢谢。

+0

你有7个问题,得到7个答案,但没有接受。接受答案 - 和投票 - 帮助别人找到好帖子。 [旅游]解释SO如何工作。 – Plutonix

+0

您不能在Load事件中隐藏()表单。 Load事件触发是因为您使用了Show()。您必须返回并找到创建表单的代码,这就是If语句所属的代码。但是你可能想继续这样做,使用Close()来代替,然后使用Project> Properties> Application选项卡> Shutdown mode =关闭上一个窗体。 –

+0

是的,这是....谢谢 – Jamyz

回答

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 

还记得到窗体2或你的程序下加入将保持关闭窗体2后打开。

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