-
Private Sub ACTIVECLOSEToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ACTIVECLOSEToolStripMenuItem.Click
Dim Nform As New Aba_Principal_SecondShift
Nform.Show()
Hide()
End Sub
Private Sub CREATEWORKNUMBERToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles CREATEWORKNUMBERToolStripMenuItem.Click
Dim Nform2 As New Aba_Principal_ThirdShift
Nform2.Show()
Hide()
End Sub
我的问题是,如果我执行相反的过程,则会出现以下错误:“无法添加引用。将该项目添加为引用会导致循环依赖。”
答案 0 :(得分:1)
也许这将有助于:
我刚刚修改了您的代码,已将fc声明为一种形式,并为其指定了一个值
在您的应用程序中打开表单,之后我创建了一个if statement
,如果fc
是一个开放表单,则将其关闭并显示您要显示的表单。
PS:请不要忘记在代码中添加Try Catch Exception
,以防止应用程序崩溃。
Private Sub ACTIVECLOSEToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ACTIVECLOSEToolStripMenuItem.Click
Dim fc As Form = Application.OpenForms("Form2")
If fc IsNot Nothing Then fc.Close()
form1.Show()
End Sub
Private Sub CREATEWORKNUMBERToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles CREATEWORKNUMBERToolStripMenuItem.Click
Dim fc As Form = Application.OpenForms("Form1")
If fc IsNot Nothing Then fc.Close()
form2.Show()
End Sub
答案 1 :(得分:0)
正如吉米(Jimi)在评论中所说,您无需使新表格变暗;您只需要使用.show()
打开它们,如下所示。假设您已经调用了您的第一个表格Nform1
,而您调用了第二个表格Nform2
。如果没有,只需将名称替换为您选择的名称
Private Sub ACTIVECLOSEToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ACTIVECLOSEToolStripMenuItem.Click
Nform1.Show()
Me.Close()
End Sub
Private Sub CREATEWORKNUMBERToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles CREATEWORKNUMBERToolStripMenuItem.Click
Nform2.Show()
Me.Close()
End Sub
关闭启动表单时可能会遇到问题,因为默认情况下,Visual Basic会在发生这种情况时关闭整个程序,如下面Shutdown mode:
所示
您可以将其更改为When last form closes
:
您可以在项目的设置应用程序选项卡中找到它们。以下是在哪里找到它的示例: