2017-04-22 50 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 
相關問題